ThisWillDoIt ThisWillDoIt - 9 months ago 59
ASP.NET (C#) Question

Log4net won't send data to "Logentries"

I am trying t to log some data to with log4net.

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

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) {
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:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, 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, " />
<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" />
<level value="ALL" />
<appender-ref ref="LeAppender" />
<appender-ref ref="FileAppender" />

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

Answer Source

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.