简体   繁体   English

NLog-帮助了解现有配置选项

[英]NLog - Help Understanding existing configuration options

I'm using NLog on an application. 我在应用程序上使用NLog。 I copied over NLog configuration settings from another project. 我从另一个项目复制了NLog配置设置。 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. 我很好奇配置指定的内容,特别是“归档”选项。 (ie maxArchiveFiles, archiveEvery). (即maxArchiveFiles,archiveEvery)。

Also, I noticed that currently when I log anything using NLog, it spits out two files. 另外,我注意到当前使用NLog记录任何内容时,它会吐出两个文件。 An exceptions.txt file and a log.txt file. 一个exceptions.txt文件和一个log.txt文件。 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. 现在,我仅记录错误/异常,因此,即使它与exceptions.txt相同,我也不认为我甚至不需要logs.txt文件。

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

It's creating two files (logs.txt and errors.txt) because you're specifying two files (target name=file, target name=errors). 它正在创建两个文件(logs.txt和errors.txt),因为您要指定两个文件(目标名称=文件,目标名称=错误)。

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: 这是说明格式和选项的文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM