Question

Below is the Section of log4net from app.config

   <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,     log4net" />
   </configSections>      
   <log4net debug="true">
     <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <file type="log4net.Util.PatternString" value="${TMP}\SRG\Logs\Log_%env{USERNAME}_%date{yyyyMMdd}.log" />
      <appendToFile value="true" />
      <bufferSize value="20" />
      <LockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <layout type="log4net.Layout.PatternLayout">
      <header type="log4net.Util.PatternString" value="[Log Starts]%newline" />        
      <footer type="log4net.Util.PatternString" value="[Log Ends]%newline" />        
      <conversionPattern value="%date [%username] - %message%newline" />
      </layout>
     </appender>  

     <logger name="SRGApplicationDebugLog">
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
     </logger>
   </log4net>  

Problem 1: I am getting header and footer two times extra whenever my application is started, but I need to avoid it.

[Log Starts]
[Log Ends]
[Log Starts]
[Log Ends]
[Log Starts]
2012-11-08 12:25:03,376 [username] - Application started
[Log Ends]

Problem 2: I am not getting from where is the two empty header footer pair is coming.

  1. I am creating logger like below:
_debugLogger = LogManager.GetLogger("SRGApplicationDebugLog");    
XmlConfigurator.Configure(); 
  1. To use Logger:
_debugLogger.DebugFormat(logMessage);    
  1. I have added this line explicitly in AssemblyInfo.cs for log4net
[assembly: XmlConfigurator(Watch = true)]    

Question: Want to fix the problems in bold

Was it helpful?

Solution

You don't need

 XmlConfigurator.Configure();

if you have

[assembly: XmlConfigurator(Watch = true)]

Having both will result in the two headers and two footers.

As to why you have three sets, perhaps you are calling XmlConfigurator.Configure() twice.

OTHER TIPS

Putting XmlConfigurator.Configure() at more than one places may result in having more >than one header and footer pair.

XmlConfigurator.Configure() should be defined only at one place in the solution. Better >approach is to put it in AssemblyInfo.cs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top