如何在后面的代码中包含NLog配置文件

问题描述 投票:0回答:1

我有一个nlog.config文件,其中包含以下条目:

<include file="${basedir}/ActiveConfig/NLog/*.config"/>

但是我想通过后面的代码解决这个问题,但是还没有找到一种解决方法。

LogManager.LoadConfiguration()

正在覆盖我现有的配置。

我错过了什么吗?

c# .net nlog
1个回答
0
投票

认为简单的解决方案是将所有配置文件加载到内存流中,然后将其加载到单个XmlLoggingConfiguration中:

var xmlReader = System.Xml.XmlReader.Create(memorystream);
NLog.LogManager.Configuration = new XmlLoggingConfiguration(xmlReader, null);

类似这样,您将所有配置文件的内容放在同一<nlog> -root中:

<nlog>
   <!-- XML File 1 -->
   <targets>
   </targets>
   <rules>
   </rules>
   <! -- XML File 2 -->
   <targets>
   </targets>
   <rules>
   </rules>
</nlog>
© www.soinside.com 2019 - 2024. All rights reserved.