使用Nlog登录多个文件 [英] Logging in multiple files using Nlog

查看:144
本文介绍了使用Nlog登录多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NLog进行日志记录.

I am using NLog for logging purpose.

我的代码如下:

<?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">

  <!-- 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="logfile"
      xsi:type="File"
      layout="${message}"
      fileName="${basedir}../Data/debugLog1.txt"
      archiveAboveSize ="5000000"
      maxArchiveFiles="2"/>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="logfile" />
  </rules>
</nlog>

我正在将数据记录在debugLog1.txt中.现在从项目中的另一个位置我也想记录数据,但是该数据是另一个 键入,因此我想创建一个debugLog2.txt并将数据记录到它.如何修改上面的代码来做到这一点

I am logging data in debugLog1.txt. Now from another location in project I also want to log data but this data is of another type so I want to make a debugLog2.txt and log data to it. How can I modify my above code to do this

推荐答案

我认为您需要定义另一个记录器.

I think you need to define another logger.

<logger name="SpecialLogger" minlevel="Trace" writeTo="logfile2" />

然后进入项目日志中的另一个位置:

And then into this another location in project log to it:

var logger = LogManager.GetLogger("SpecialLogger");

这篇关于使用Nlog登录多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆