I really wish someone could help me with that. It is really driving me crazy.
I have a simple simple Windows Forms application and I am trying to use the log4net library for logging (I am just testing it in this project because it didn't work out in my main project).
So I have the regular Form1.cs, app.config, AssemblyInfo.cs and Program.cs.
In my app.config I have:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Your Header text here]" />
<footer value="[Your Footer text here]" />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc]
<%property{auth}> - %message%newline" />
</layout>
</appender>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
In the Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using log4net;
using log4net.Config;
namespace log4net.test
{
public partial class Form1 : Form
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
log.Debug("This is a DEBUG level message. The most VERBOSE level.");
log.Info("Extended information, with higher importance than the Debug call");
log.Warn("An unexpected but recoverable situation occurred");
}
}
}
And in the end of the AssemblyInfo.cs file I have added:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "app.config", Watch = true)]
When I debug and go to the button1_Click I can see that nothing is happening. The log object has its:
IsInfoEnabled, IsDebugEnabled, IsErrorEnabled, IsWarnEnabled set to false and just nothing happens.
I've been trying to find a solution all day long and nothing. Can somebody help?