4

I have log4net configured and working fine on my local machine, however when I deploy to my host (godaddy) it fails silently. I am using the same database/config file on my dev machine, and on the host. My log4net reference is set to copy local, and the log4net.dll, .pdb, and .xml exist in the bin on the host. This is an asp.net mvc app.

Edit: No exceptions are thrown, and the application runs as expected (minus the logging)

This is running on SQL Server 2005 The webhost is IIS 7

salient details of my config are:

<root>
  <level value="DEBUG" />
  <appender-ref ref="AdoNetAppender" />
</root>

<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="1" />

  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Anybody have any ideas on things to check?

jlnorsworthy
  • 3,914
  • 28
  • 34

2 Answers2

7

In my experience, log4net usually swallows any internal errors, simply resulting in log statements that do not produce any results.

What you may want to try is enable log4net's internal logging. You can do this by adding the following to your appSettings section:

<add key="log4net.Internal.Debug" value="true" />

This sets the property LogLog.InternalDebugging to true. log4net will now log to the standard output and error streams and to configured trace listeners.

You can use the following configuration to capture any messages logged to tracing:

<system.diagnostics>
  <trace autoflush="false" indentsize="4">
    <listeners>
      <add name="myListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="c:\TextWriterOutput.log" />
      <remove name="Default" />
    </listeners>
  </trace>
</system.diagnostics>

All messages logged by log4net internally will appear in TextWriterOutput.log. If you get a SecurityException when you add the trace listener to your configuration, then very probably the apppool identity does not have sufficient rights to create a file at the specified location (in the example: c:\). Try another location or give the apppool identity sufficient rights.

Ronald Wildenberg
  • 31,634
  • 14
  • 90
  • 133
  • Thanks for the help Ronald. I assume I'd need to add a DebugListener to log the exceptions to a file? For some reason I can create a file on the shared host by using a TextWriter and writing to the file, but I get a security exception when trying to specify the same path and adding it as a DebugListner (after clearing existing listeners) I know this is really a separate question, but do you have any ideas on this? – jlnorsworthy Aug 23 '10 at 00:08
  • Do you have more info on this SecurityException? Possibly your application pool identity doesn't have sufficient permissions to write to the specified location. – Ronald Wildenberg Aug 23 '10 at 07:54
  • System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. From Elmah logging: The action that failed was: LinkDemand The type of the first permission that failed was: System.Security.Permissions.SecurityPermission The Zone of the assembly that failed was: MyComputer This is running on godaddy (medium trust). – jlnorsworthy Aug 23 '10 at 21:24
  • I added some additional info to my answer. I just tested this setup on my local machine and the trace listener output file contained internal log4net messages, so I'm sure that it can work. If you can just get rid of the trace listener's SecurityException, you'll find out why log4net isn't logging anything. – Ronald Wildenberg Aug 23 '10 at 22:12
  • Marking as answer - the next question (don't worry, I'll ask separately :D) is: can you add debug/trace listeners in medium trust – jlnorsworthy Aug 30 '10 at 07:19
1

I've just been able to resolve this problem by downloading and using the latest build of log4net (revision 1072765) from SVN repository http://svn.apache.org/viewvc/logging/log4net/trunk/

Apparently this problem has been fixed long time ago but who knows when log4net 1.2.11 is going to be released.

10p
  • 5,488
  • 22
  • 30