tags:

views:

23

answers:

1

Hi,

I am trying to implement a simple log using Nlog 1.0, using the following code

  Dim _logger = LogManager.GetCurrentClassLogger()
  _logger.Debug("Iain")

And the following NLog.config.

<?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="file" xsi:type="File" fileName="${basedir}/Site.log" layout="${date}: ${message}"/>
    <target name="eventlog" xsi:type="EventLog" source="My App" log="Application" layout="${date}: ${message} ${stacktrace}"/>
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="file" />
    <logger name="*" minlevel="Fatal" writeTo="eventlog" />
  </rules>

</nlog>

The app just dosnt seem to be logging, any ideas?

Cheers

Iain

+2  A: 

The minLevel is not set to log Debug messages.

NLog levels are:

  • Fatal
  • Error
  • Warn
  • Info
  • Debug
  • Trace

When you have minLevel set to Info, it will only log Info and higher; Debug and Trace messages will not be logged.

adrift
That did not seem to work
Iain
Did you set the minLevel to "Debug" or "Trace"?
adrift
I tried both Debug and Trace
Iain
Hmm... I have NLog 1.0 logging to both file and sql server. By any chance, are you using this in a web app in the asp.net development server? I have noticed that I need to shut down the asp.net dev server process to have it refresh settings, though I cannot remember specifically if that was for NLog.
adrift
I am running a windows forms application, bassically trying out Nlog, no real code apart from what i included/
Iain
Ok, I think I know what is happening. The nlog config file has to be in the output directory. Did you set the 'Copy to Output Directory' property to 'Copy Always'?
adrift
that did the trick, thank for your help
Iain
you're welcome, glad I could help
adrift