0
votes

I'm using NLog on an application. I copied over NLog configuration settings from another project. The file looks like this:

<?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" autoReload="true">

  <!-- make sure to set 'Copy To Output Directory' option for this file -->
  <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

  <targets>
        <target name="file" xsi:type="File" fileName="${basedir}/logs/log.txt" />
        <target name="errors" xsi:type="File" maxArchiveFiles="7" layout="${longdate}|${level}|${callsite}|${message}|${exception:format=ShortType,StackTrace}" archiveEvery="Day" fileName="${basedir}\logs\exceptions.txt" />    </targets>
    <rules>
        <logger name="*" minlevel="Debug" writeTo="file,errors" />
    </rules>
</nlog>

I'm curious what the configuration is specifying, in particular the "archive" options. (i.e. maxArchiveFiles, archiveEvery).

Also, I noticed that currently when I log anything using NLog, it spits out two files. An exceptions.txt file and a log.txt file. I guess I expected that the exceptions file would only contain exceptions (it logs warnings and information to the exceptions text file).

Right now I'm only logging errors/exceptions, so I don't think I even need the logs.txt file if its just the same thing as the exceptions.txt.

C#, NLog v2.0.0.0, ASP.NET 4

1
Have you gone to NLog at all and read about the config file? nlog-project.org/wiki/Configuration_file - Gratzy

1 Answers

0
votes

It's creating two files (logs.txt and errors.txt) because you're specifying two files (target name=file, target name=errors).

That's probably a good idea, but you're certainly free to experiment with different combinations of settings and files, and standardize on whatever suits you best.

Here's the documentation explaining the format and options: