ThisWillDoIt ThisWillDoIt - 1 month ago 13
ASP.NET (C#) Question

Log4net won't send data to "Logentries"

I am trying t to log some data to www.logentries.com with log4net.

My problem is that everything I try to log gets shown in the FileAppender but no data is shown on logentries.com.

I tried to get some error information and enabled log4net internal logging, but that file doesn't contain any error messages.

I am really clueless at this point where to check for possible errors...

The basic logging code is just this piece of code

private static readonly ILog logger = LogManager.GetLogger(typeof(Logentries));

static void Main(string[] args) {
XmlConfigurator.Configure();
logger.Fatal("Fatal message");
}


I added this line to my AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "App.config", Watch = true)]


My App.config is set up like this:

<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="LeAppender" type="log4net.Appender.LogentriesAppender, LogentriesLog4net">
<ImmediateFlush value="true" />
<Debug value="true" />
<HttpPut value="false" />
<Ssl value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{ddd MMM dd HH:mm:ss zzz yyyy} %logger %: %level%, %m, " />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LeAppender" />
<appender-ref ref="FileAppender" />
</root>
</log4net>

<appSettings>
<add key="Logentries.Token" value="XXXXXX-XXXXXX-XXXXXXXXX-XXXXXXX" />
<add key="log4net.Internal.Debug" value="true" />
</appSettings>

Answer

The solution is to wait long enough after the (last) log entry was made. Either with enough code after it, or if it is unsure how long it takes to execute the code with a Thread.Sleep(1000) or something similar.
The reason for this seems to be that since logentries appender works internally asynchronous my program could finish and terminate the logging thread before the logs could be send to the server. Unfortunately there is no real indication that this happend.

Comments