0

Hi I have created a custom log4net appender and I can get the appender to work in a console application. However when I try and use the appender in a MVC web app or even in an ASP.NET web app it fails to run the appender.

The log4net config is in a separate file.

Here is the config:

<appender name="AsynchronousLog4NetAppender" type="Custom.ErrorLogger.CustomErrorLogger, CustomErrorLogger">
    <file value="App_Data\Logs\Trace.%property{log4net:HostName}.log" type="log4net.Util.PatternString" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
    </layout>
    <encoding value="utf-8" />
</appender>

I have made sure that the IIS user has full control on the directory and still does not work. If I use a standard appender everything works. I have checked this post (log4net with ASP.NET MVC: nothing happens).

TIA

Graham Harris

Community
  • 1
  • 1
Graham Harris
  • 319
  • 1
  • 2
  • 16
  • 1
    Try checking the [internal debugging](https://logging.apache.org/log4net/release/faq.html#internalDebug) for messages about the appender failing. As you're in a non-interactive environment you'll need to hook up a trace listener to make this work. If there are *no* messages about the appender, you know it's not initialized. If there are messages but no apparent errors, you'll need to dig even deeper (like breaking out [Procmon](https://technet.microsoft.com/en-us/sysinternals/processmonitor) to see failing file system calls). – Jeroen Mostert Apr 24 '17 at 13:01
  • Found the problem, there was a '' section which was preventing log4net from working. – Graham Harris May 03 '17 at 05:21

0 Answers0