Exception when using Console target

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

Exception when using Console target

dtarczynski
Hello
Im using Console target configured in Appname.exe.config as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <nlog>
    <targets>
      <target name="console" type="Console" layout="${date:format=HH\:MM\:ss} ${logger} ${message}"/>
    </targets>

    <rules>
      <logger name="*" minLevel="Info" writeTo="console"/>
    </rules>
  </nlog>



</configuration>


When i tried start logging Im getting exception:
The type initializer for 'NLog.LayoutRendererFactory' threw an exception.

Im getting this exception at first line of my code:
ConsoleTarget target = new ConsoleTarget();
            target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

            Logger logger = LogManager.GetLogger("Example");
            logger.Debug("log message");




Im using .NET 2.0 framework and the newest wersion of Nlog.

Please help. Thanks in advance
Dariusz Tarczynski
Reply | Threaded
Open this post in threaded view
|

Re: Exception when using Console target

Jarek Kowalski
Administrator
There are two options:

Either put the config in AppName.exe.nlog so that the root element of the file is <nlog> and remove it from AppName.exe.config

OR

Add the required configSections/section handler to AppName.exe.config

<?xml version="1.0" encoding="windows-1250" ?>
<configuration>
    <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
    </configSections>
    <nlog>
        ...
    </nlog>
</configuration>
   
Regards,

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Exception when using Console target

dtarczynski
Thaks! This resolve my problem.

Pozdrawiam :-)