【发布时间】:2015-07-30 21:05:50
【问题描述】:
我对 NLog 有一个独特的问题。我有一个我们在项目中使用的第三方程序集。他们已经在他们的项目中使用了 NLog,并将 NLog 配置引用到我无权访问的配置中。 最初我什至将 NLog 添加到项目中时遇到了问题,因为两个版本的 dll 都不同。我不得不下载 NLog 的源代码并更改程序集名称,因为别名对我不起作用(或者我不知道如何使用它。) 在给出我自己的程序集名称后,NLog 开始工作,但是.. 它也开始记录第三方日志信息。看起来他们在定义记录器时不够小心,他们只是定义了(*)。现在我的问题是,我如何避免他们的东西登录到我的文件?我也尝试将其设置为 final = true。 这是我非常简单的配置文件的样子。
<?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">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target name="errorLog" xsi:type="File"
fileName="${basedir}/logs/error/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
/>
<target name="generalLog" xsi:type="File"
fileName="C:/logs/${date:format=yyyy-MM-dd}.log"
layout="${longdate} ${uppercase:${level}} ${message}"/>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="Errors" writeTo="errorLog" minlevel="Warn"/>
<logger name="EBusiness.Model.*" writeTo="generalLog" levels="Trace,Debug,Info" final="true"/>
<!--
<logger name="*" minlevel="Trace" writeTo="f" />
-->
</rules>
</nlog>
【问题讨论】: