« January 2008 | Main | September 2008 »
July 17, 2008
Log4Net with ASP.NET
You can read about it and set it up but it won't work for you and nobody tells you why.
Essentially this is a permissions issue.
You will first need to know that on Windows Server 2003 the user you needto worry about is not 'ASPNET' but 'NETWORK SERVICE'. In Win2k and XP the user is indeed 'ASPNET'.
When you set up the Log4Net as shown in the exmaples on the Log4Net site it will work, the configuration will be correct etc. The problem will be that the entries will not appear in the Event Log.
The reason is that the default Application Name (the 'Source' column in the event viewer) is governed by a key that must be added to the registry.
The NETWORK SERVICE and ASPNET users do not have permission to set this key, so while the log messages are being passed to the Event Log, they are being dropped because there is no match application key in the registry and the users cannot create it.
If your first impulse was to add the NETWORK SERVICE and ASPNET users to the Administrators group then stop right there, don't do it, especially not on a Production server. It is not necessary. Once the application key is set in the registry your permission problems are over.
First thing, you will want to open regedit and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
The right click on the Application node and add a new key. The name of this new key is up to you. But for arguments sake lets choose 'BingoBango'.
That part is over with, close your regedit (you did back up the registry before you started changing things didnt you??!)
Now in your log4net configuration file you will want to set up your appender like this:
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<param name="ApplicationName" value="BingoBango" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
And you should see your log entries appearing.
Have fun!
Posted by dottie at 3:06 PM | Comments (0) | TrackBack