log4Net log file not writing
21,333
Solution 1
Make sure you are calling the Configure function of the XmlConfigurator.
See this solution: Configure Log4Net in web application
Solution 2
Try to give write permission in E:/Log for asp.net user or for Everyone, then try to add requirePermission="false" attribute, like this:
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" requirePermission="false" />
or you should specify logging level in root section, like this:
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
here ASP.NET 3.5 – File Appender sample application
Related videos on Youtube
Author by
Shibin V.M
Updated on October 23, 2020Comments
-
Shibin V.M over 3 years
I am trying to implement log4net in my asp.net web application. But unfortunately the file is not created. Below is my configuration.
1 . Added log4net .dll reference
2 . Web.config settings.
<configSections> <section name="log4net"type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> </configSections> <log4net> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="E:/Log/error_%date{dd-MM-yyyy}.log"/> <appendToFile value="true"/> <rollingStyle value="Date"/> <!--<maxSizeRollBackups value="5"/> <maximumFileSize value="10MB"/> <staticLogFileName value="true"/>--> <datePattern value="yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception%newline%newline"/> </layout> </appender> <root> <appender-ref ref="RollingFileAppender"/> </root> </log4net>
3 . Added Assembly reference
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
4 . Log writing in the code behind
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { throw new System.IO.FileNotFoundException(); } catch (Exception ex) { log.Error("Error error logging", ex); }
These are the steps I had followed, but the log is not created...
Please give your suggestions.
Thanks in advance
-
Christian Westman over 11 yearsare you sure you have write permission to E:/Log/error_%date{dd-MM-yyyy}.log ?
-
-
erlingormar over 7 yearsPermissions tripped me up. Good catch.