Hi there,
I'm just starting with NLog and trying a few simple examples. I made a console app with the following nlog.config:
<nlog xmlns="
http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/file.txt" layout="${stacktrace} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file"/>
</rules>
</nlog>
Then I used the following code inside the program.cs file:
private static Logger mLogger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
mLogger.Trace ("NLog test -> Trace");
mLogger.Debug ...
...
Console.ReadLine();
}
All worked as expected.
Now I wanted to do the same from a WinForm app. I used exactly the same nlog.config. My form1.cs only has a single button in the GUI. The code looks like this:
public partial class Form1 : Form
{
private static Logger mLogger = LogManager.GetCurrentClassLogger();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
mLogger.Trace ("NLog test -> Trace");
mLogger.Debug ...
...
}
}
The button1_Click runs, but nothing happens in this case. Can anybody give me any hint what I have to change?
I changed to code configuration in the gui-button example and there it worked well. So what is my problem? Is there any initializing call missing? Or is there a WinForm example somewhere that I did not find?
Thanks for any help
Tom