【问题标题】:How can I use machine.config settings in the NLog.config如何在 NLog.config 中使用 machine.config 设置
【发布时间】:2016-04-14 14:10:18
【问题描述】:

是否可以在 Nlog.config 中使用 machine.config 设置?

例子

       <nlog>
          ...
          <target name="database" xsi:type="Database" 
keepConnection="true" dbDatabase="xxx" 
dbHost="**MACHINE_CONFIG_SETTING**" 
commandType="StoredProcedure"  dbProvider="System.Data.SqlClient" dbUserName="**MACHINE_CONFIG_SETTING**"
 dbPassword="**MACHINE_CONFIG_SETTING**" 
  connectionString="**MACHINE_CONFIG_SETTING**"
          commandText="stored_proc">
    </nlog>

我们在机器配置中有 dbhost 名称和 dbUsername,所以我真的不想在 Nlog 配置中复制这些信息。 如果可以的话,我不想将整个 Nlog 配置放在机器配置中。

非常感谢任何帮助。

【问题讨论】:

    标签: c# nlog machine.config


    【解决方案1】:

    这应该是可能的,但你不能部分覆盖它。

    你也可以使用&lt;include file="${basedir}/${machinename}.config"/&gt;进行复用,更灵活一点。

    【讨论】:

    • 感谢您的回答。我实际上使用 LogManager.Configuration 来获取目标并将其转换为我的代码中的数据库目标,然后使用 System.Configuration 从机器配置中获取我需要的配置。工作了一个享受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    相关资源
    最近更新 更多