Log4net configuration error
c#, log4net, logging
Solution
A working configuration for Rolling File appender is like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="logger.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger [%thread] [%ndc] (%file:%line) %level- %message%newline"/>
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
</log4net>
</configuration>
and you should change your target framework to ".net framework 4" (by default it is different in my case) check this one will be useful
Problem
I am using Log4Net to log exceptions in my web application. Here I have found an example for a configuration: http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin ``` <?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> </configSections> <log4net> <!-- This writes the log information to the console window. It only logs events that are at least at the INFO level (which would mean that DEBUG events are not captured. --> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{ABSOLUTE} [%thread] %level %logger - %message%newlineExtra Info: %property{testProperty}%newline%exception"/> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="INFO"/> <levelMax value="FATAL"/> </filter> </appender> <!-- This stores information in the log.txt file. It only captures log events that contain the key word test or error. --> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="L:\Name\trunk\Name.Web\log.txt"/> <appendToFile value="true"/> <rollingStyle value="Size"/> <maxSizeRollBackups value="5"/> <maximumFileSize value="10MB"/> <staticLogFileName value="true"/> <filter type="log4net.Filter.StringMatchFilter"> <stringToMatch value="test"/> </filter> <filter type="log4net.Filter.StringMatchFilter"> <stringToMatch value="error"/> </filter> <filter type="log4net.Filter.DenyAllFilter"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/> </layout> </appender> <root> <level value="FATAL"/> <appender-ref ref="RollingFileAppender"/> </root> <logger name="Log4NetTest.OtherClass"> <level value="DEBUG"/> <appender-ref ref="ConsoleAppender"/> </logger> </log4net> </configuration> ``` In my class I have: ``` protected static readonly ILog log = LogManager.GetLogger(typeof(TemplateController)); ``` and in my method I have: ``` log4net.Config.XmlConfigurator.Configure(); //————————– log.Error("sadi the great"); log.Info("sadi the great"); ``` but I have got error: