NLog does not show any output!

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

NLog does not show any output!

sheperson
Hi,
I have downloaded and installed the latest version of NLog and tried the sample project on the NLog documentation (in the introduction page), but no output appears on the console.
I am using Visual Studio 2010 and the project configuration is for .net 4.0.

And if I change the target framework to 2.0, again nothing happens.

Here is the code:
================================
using System;
using System.Collections.Generic;
using System.Text;
using NLog;

namespace NLogTest
{
    public class Program
    {
        private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
        static void Main(string[] args)
        {
            logger.Debug("Hello world!");
        }
    }
}
================================
and the NLog.config file:
================================
<?xml version="1.0" encoding="utf-8" ?>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
      <target name="Console" xsi:type="Console" layout="${longdate}|${level}|${message}" />
    </targets>

    <rules>
      <logger name="*" minlevel="Debug" writeTo="Console"></logger>
    </rules>
</nlog>

================================

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

Francis1
I've been using NLog for years and just tried NLog 2010.07.22.001 and I observed the same issue:  no logging occurs in .NET 4.

I did not change the NLog.dll.nlog file contents which are:

<?xml version="1.0" encoding="utf-8" ?>
<nlog autoReload="true"
          internalLogFile="nlog.txt"
          internalLogLevel="Error"
          xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


<targets>       

<target name="info" xsi:type="File" fileName="${basedir}/../logs/${shortdate}/log.txt" layout="${longdate}|${level:uppercase=true}|${logger}|${threadid}|${callsite}|${message}"/>
<target name="network" xsi:type="Chainsaw" address="udp://localhost:7071" /> 
</targets>

<rules>
<logger name="*" level="Info" writeTo="info,network" />
</rules>
</nlog>

The fact that no errors occur suggests NLog is not loading the config file.
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

vyas
In reply to this post by sheperson
Hi Francis1,


Which remote log listener you are using.


Thanks,
Vyas



Vyas
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

xingon
In reply to this post by sheperson
hi,guy.Nlog.Config doesn't work in console application.you can use setting in app.config.

steps as below
1) add configsection

2) add <Nlog>.....node in app.config


then try it again. it's perfect in web appliction using Nlog.config but console application.

Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

sheperson
Hi,
Thank you guys, I figured it out.
NLog was not reading the NLog.config!
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

Francis1
In reply to this post by vyas
Hi Vyas,

I am using log2console on a x64 machine with the project running in x86 mode because of some dlls I can't recompile.
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

nlogger
In reply to this post by sheperson
nlog doesn't log in my unit test.

I have a unit test project in my console solution.  In the console project, it NLog works just fine and writes log messages nicely into a file "log.txt", but in my unit test project, it refuses to write log messages to file.  The NLog.config file in the console project and the NLog.config file in the unit test project are completely the same.

I am using NUnit.

Any idea how to fix this?
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

Francis1
The NUnit config file should probably be in your NUnit install folder because that's where the executable is.
Reply | Threaded
Open this post in threaded view
|

Re: NLog does not show any output!

ignat
In reply to this post by sheperson
I had a such problem. Solved by changing NUnit settings as follows:
[Assembly Isolation]
Default Process Model=Run tests in a single separate process
Default Domain Usage=Use a separate process per Assembly

And yes, NLog.config file should be placed in the same folder with tested assembly.