0

i observe a strange behavior when using Seq.Client.log4Net (3.1.0) on .NET 6 :

logging to the Seq Server seems to work only if I call XmlConfigurator.ConfigureAndWatch before and after calling the log method. It seems that only the Seq appender is affected (Console and File Logging are executed without the second call of XmlConfigurator.ConfigureAndWatch!

Logging to Seq Server works fine:

 ILog log = LogManager.GetLogger(GetType());
 XmlConfigurator.ConfigureAndWatch( new FileInfo(@"\log4net.config"));
 log.Info("Entering application.");
 log.Warn("Exiting application.");
 XmlConfigurator.ConfigureAndWatch(new FileInfo(@"log4net.config")); //why is this required??

No Seq Logging:

 ILog log = LogManager.GetLogger(GetType());
 XmlConfigurator.ConfigureAndWatch( new FileInfo(@"\log4net.config"));
 log.Info("Entering application.");
 log.Warn("Exiting application.");

log4net.config is:

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">      
 ..    
    </appender>
    
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
 ..
    </appender>
    
    <appender name="SeqAppender" type="Seq.Client.Log4Net.SeqAppender, Seq.Client.Log4Net">
      <bufferSize value="100" />      
      <serverUrl value="https://xxx:yy" />
      <apiKey value="" />
      <parameter>
        <parameterName value="Runtime" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value=".NET Framework" />
        </layout>
      </parameter>
      <parameter>
      <parameterName value="Config" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="ExternalConfig" />
      </layout>
      </parameter>     
    </appender>
   
    <root>
      <level value="DEBUG" />
      <appender-ref ref="ConsoleAppender" />
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="SeqAppender" />
    </root>
  </log4net>

according to the documentation one call to ConfigureAndWatch is enough, so I am very confused what is going on here. hanks for any ideas!

1 Answers1

1

You need to call LogManager.Shutdown() before exiting the application to ensure all events are flushed to Seq.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • O. k., many thanks for the hint. This seems to work indeed. But it seems to me a bit ineffective to shut down the locking system after each log message, and then create a new log manager again at the next logging, also reading the configuration file each time. Is there no other way? – Daniel Devo Nov 10 '22 at 07:59
  • Ah, and in fact logging is no longer possible after showdown, which is impractical for a web application, for example. – Daniel Devo Nov 10 '22 at 08:43
  • Logging needs to be set up once when your app starts, and shut down when your app shuts down - not per request, in case that helps – Nicholas Blumhardt Nov 11 '22 at 01:01
  • No, unfortunately this idea doesnt't help. because with a web application there is no showdown. – Daniel Devo Nov 14 '22 at 14:04