tags:

views:

819

answers:

1

Hi, this is my configuration for log4net:

<log4net>
 <appender name="MyLogger" type="log4net.Appender.RollingFileAppender">
  <file value="MyLog.log" />
  <appendToFile value="true" /> 
  <rollingStyle value="Size"/>
  <maxSizeRollBackups value="20"/>
  <maximumFileSize value="1000KB"/>
  <layout type="log4net.Layout.PatternLayout">
   <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss},%p,%m%n" />
  </layout>
 </appender>
 <root>
  <level value="DEBUG" />
  <appender-ref ref="MyLogger" />
 </root>
</log4net>

In C# I'm trying to get the name of the log file (which is MyLog.log). I googled and tried many things but failed to do so. Any help?

Thanks!

+2  A: 

Hi, solution is quite easy in your situation, just use this code:

FileAppender rootAppender = (FileAppender)((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Appenders[0];
string filename = rootAppender.File;
Yakeen
Worked like a charm. Thanks!
Carlo