my FileAppender isn't working. It probably isn't a permissions thing as I'm local admin.
I've enabled internal debugging and I'm not getting any errors or exceptions from log4net.
My config file is below. Thanks
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
The code to log is effectively:-
public class Logger
{
private static readonly ILog defaultLog;
static Logger()
{
BasicConfigurator.Configure();
defaultLog = LogManager.GetLogger("default");
}
public static void Log(string errorMessage, Exception exception)
{
defaultLog.Error(errorMessage, exception);
}
}
Based on your description I assumed, that you used the BasicConfigurator (supports only ConsoleAppender) instead of the XmlConfigurator. Switching to the XmlConfigurator should fix your problem.
There are 2 main options to enable logging. Refer to the Configuration manual for more details.
XmlConfigurator.Configure()
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
to AssemblyInfo.cs
BasicConfigurator.Configure() can only write to the console.
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