No Logs in WinForm

3 messages Options
Embed this post
Permalink
Tom

No Logs in WinForm

Reply Threaded More More options
Print post
Permalink
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
Jaroslaw Kowalski

Re: No Logs in WinForm

Reply Threaded More More options
Print post
Permalink
1. Can you verify that NLog.config is being copied to output directory (this is not automatic and you have to select "Copy to output directory") option in VS.

2. If that doesn't work, can you zip and send the whole project to me? jaak -at - jkowalski -dot- net?
Tom

Re: No Logs in WinForm

Reply Threaded More More options
Print post
Permalink
Thanks for your help. #1 was the problem. I did it like the step by step guide for the console app, but simply forgot the step in the win form project.