Question

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>
Was it helpful?

Solution

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 Task.Delay(1000) or something similar.
The reason for this seems to be that since logentries appender works asynchronous internally the 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.

OTHER TIPS

I had pretty much the same issue. Nothing was logged to Logentries even if everything seemed to be setup correcly. Other appenders were working.

I enabled log4net debug logging (see How to track down log4net problems)

...and it turned out to be a version issue in my case. LeAppender needed version 1.2.13.0 of log4net and my application was using 1.2.10.0:

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [LeAppender] of type [log4net.Appender.LogentriesAppender, LogentriesLog4net]. Reported error follows.
System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

You may want to change the appender's locking model to include MinialLock

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

http://www.codeproject.com/Articles/140911/log-net-Tutorial

Well probably this is a very late reply now, but I was facing the same issue and could not find anything productive on net for days and days. Until eventually i just found the solution and thought of updating here as it may help someone.

The solution is fairly straightforward. Instead of this

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

Include the token inside the tag itself.

<appender name="LeAppender" type="log4net.Appender.LogentriesAppender, LogentriesLog4net">
    **<Token value="XXXXXX-XXXXXX-XXXXXXXXX-XXXXXXX"/>**
    <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>

Although the documentation of Logentries mention about adding the token inside appsettings, but for some unknown reasons it does seem to pick up the token from there.

Also make sure the target .net framework of your project is >= 4.0

For your information: I am using

  1. Log4net 1.2.15

  2. LogentriesLog4net 2.8.0

  3. LogentriesCore 2.8.0

Hope this helps someone.

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