1

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

Iain
  • 6,392
  • 2
  • 30
  • 50

1 Answers1

3

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.

Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
  • Did you set the minLevel to "Debug" or "Trace"? – Jeff Ogata Oct 12 '10 at 21:25
  • 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. – Jeff Ogata Oct 12 '10 at 21:34
  • I am running a windows forms application, bassically trying out Nlog, no real code apart from what i included/ – Iain Oct 12 '10 at 21:44
  • 1
    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'? – Jeff Ogata Oct 12 '10 at 21:56