Dot-Net

有沒有辦法將 NLog.config 資訊放入我的 app.config 文件中?

  • November 5, 2014

有沒有辦法將 NLog.config 資訊放入我的 app.config 文件中?這樣我就可以擁有一個配置文件而不是兩個。它可能看起來像這樣:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="nlog" type="..." />
 </configSections>
 <nlog>
   <targets>...</targets>
   <rules>...</rules>
 </nlog>
</configuration>

請讓我知道這是否是重複的。

當然,您可以將配置放在 app.config 文件中。

你只需要使用NLog.Config.ConfigSectionHandler所以你需要寫

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
 </configSections>
 <nlog>
   <targets>...</targets>
   <rules>...</rules>
 </nlog>
</configuration>

配置文件格式部分的NLog 文件中所述。

引用自:https://stackoverflow.com/questions/26765934