首页 > 解决方案 > Asp.Net Core Web Api:从 App.config 文件中读取 Nlog 配置未加载目标

问题描述

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    </configSections>
    <nlog internalLogFile="c:\Utilities\internal_log_file.txt">
        <extensions>
            <add assembly="NLog.Web.AspNetCore" />
        </extensions>
        <targets>
            <target name="logfile"  xsi:type="file" fileName="C:/Utilities/${shortdate}_log.txt" layout="${longdate} ${level:uppercase=true} ${message}"/>
        </targets>
        <rules>
            <logger name="*" minlevel="Trace" writeTo="logfile" />
        </rules>
    </nlog>
</configuration>

当我尝试从 nlog.config 读取它时,我无法从 App.config 读取配置。

我正在尝试拥有一个可以存储在公共位置的通用配置文件,并且其他 api 也可以加载相同的配置或日志,而不是分别为每个 api 设置配置文件。

标签: asp.net-core-webapinlog

解决方案


推荐阅读