Like Dante, I’ve seen hell. Hell takes many forms depending on the sin. My sin was not knowing how to configure the ADONetAppender in log4net. The “Good News” I bring to you is how to avoid going to Log4Net hell.
First of all, if you’re having trouble with log4net, stop whatever you were doing. Go outside and take a few deep breaths. Come back to computer, and in your Web.config (or App.config) put the following lines in the configuration node:
*Note* You’ll want to remove these Web.config/App.config lines when your code is running in production *Note*
The next thing is to make sure the Assembly you’re interested in logging from, knows where to find the config file… Put this in the AssemblyInfo.cs file, for the assembly:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Ok, now everything should work, right? WRONG! You’re in Hell, remember? Your log4net.config file, should be placed in the path that is being executed. Ok, what does that mean? I’ll give an example with a wcf file structure:
webapp
someservice.svc
log4net.config <——–log4net.config should live here
web.config
bin
somedll.dll <——-Not in here
Now restart your application, and trigger a log event. You’ll see the file C:\temp\log4net.txt existing. Great. Open that file and look at it. It has all the information you need to stop pulling out your hair, banging on your desk, cussing, and any real sin you may be inclined to do.
Hopefully these simple steps keep you out of Log4Net hell.