【问题标题】:Configuration NLog.config file for using on Azure portal用于在 Azure 门户上使用的配置 NLog.config 文件
【发布时间】:2020-04-18 22:50:32
【问题描述】:

我在我的 Web 应用程序中应用了 ASP.NET core 3.1,并使用 NLog 进行日志记录。

在本地主机中,我像这样设置 internalLogFile 和 fileName

internalLogFile="E:\Archives\Projects\Alpha\Alpha.Web.App\internal_logs\internallog.txt" 
fileName="E:/Archives/Projects/Alpha/Alpha.Web.App/logs/${shortdate}_logfile.txt"

在 nlog.config 文件中。如何设置在 Azure 中使用的路径?

<?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"
      autoReload="true"
      internalLogLevel="Trace"
      internalLogFile="E:\Archives\Projects\Alpha\Alpha.Web.App\internal_logs\internallog.txt">

  <targets>
    <target name="logfile" xsi:type="File"
            fileName="E:/Archives/Projects/Alpha/Alpha.Web.App/logs/${shortdate}_logfile.txt"
            layout="${longdate} ${level:uppercase=true} ${message}"/>
  </targets>

  <rules>
    <logger name="*" minlevel="Debug" writeTo="logfile" />
  </rules>
</nlog>

nlog.config 文件在此路径中:

https://{appname}.scm.azurewebsites.net/dev/wwwroot/nlog.config

【问题讨论】:

  • 不要指定绝对路径。使用相对路径“logs\allLogs.csv”。然后从 Cloud Explorer (VS2019) 或 Server Explorer (VS2017) 中,您可以在 App Service 中找到该文件夹​​。

标签: azure asp.net-core nlog


【解决方案1】:

我使用了${basedir} 并将 internalLogFile 和 fileName 的值更改为

internalLogFile="${basedir}/internal_logs/internallog.txt">

fileName="${basedir}/logs/${shortdate}_logfile.txt"

现在我可以访问我项目中bin 文件夹中的这些文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 2016-05-01
    • 2012-06-06
    • 2019-12-14
    相关资源
    最近更新 更多