I'm using log4net 1.2.11. So, the logging is working in developer machine, but when i publish in a test server it is not working. Debugging remotely, i saw that the log is load correctly in ILog variable, but when it calls log.Error(), nothing happens, no log file, no log4net exception.
Any ideias?
Obs: i'm using the log4net in a asp.net mvc 3 website.
-- EDIT
I put Full Control to EVERYONE... nothing change, no log file.
Enable log4net debugging to get more information about the problem. Without this, log4net fails silently and it's very hard to troubleshoot configuration issues.
Check How do I enable log4net internal debugging? on log4net FAQS
Take into account if you have permissions problems (as Shyju pointed out) that the default identity for IIS 7.5 is ApplicationPoolIdentity
and not Network Service
Here you have instructions about how to secure resources for ApplicationPoolIdentity . Check section "Securing Resources"
Check the folder has sufficient permissions for ASP.NET to write a file to that. Most probably that is the reason if it worked in Dev machine
Some workarounds
in your Dev maching delete the log file and folder and run it as new and see whether it creates log file. If yes, there is nothing to change in code. It should be a permission thing. So Lets double check the permissions
As Claudio Redi mentioned in his answer, You can also enable internal debugging of log4net to get more info. Check the section called "How do I enable log4net internal debugging?" for more details in this link http://logging.apache.org/log4net/release/faq.html
From their documentation
Why can't I log to a FileAppender from a web application?
The web application runs as a special user account on the web server called ASPNET. This account has restricted permissions to protect the web server from attacks. By default this account may not have permission to write to the file system. Make sure that the ASPNET account has permission to create and write to files in the directory chosen for logging.
In my case, the reference to log4.config
inside web.config
was wrong:
<add key="log4net.Config" value="log4.config"/>
points to the root folder, and on my dev machine, log4.config
was actually there, so logging would work.
However, on a build, log4.config
is copied to the bin
folder, the only place it would be after a deploy.
Changing the web.config
to
<add key="log4net.Config" value="bin/log4.config"/>
made logging work everywhere for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With