gpt4 book ai didi

c# - 使用 NLog 登录多个文件

转载 作者:IT王子 更新时间:2023-10-29 04:13:38 48 4
gpt4 key购买 nike

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

我的代码如下:

<?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 中记录数据。现在,从项目的另一个位置,我也想记录数据,但这个数据是另一个type 所以我想制作一个 debugLog2.txt 并将数据记录到它。我该如何修改上面的代码才能这样做?

最佳答案

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

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

登录它:

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

关于c# - 使用 NLog 登录多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352325/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com