【问题标题】:NLog Logs not loggingNLog 日志不记录
【发布时间】:2020-03-24 15:17:46
【问题描述】:

我是 NLog 新手,我正在尝试在我正在编写的新应用中使用它...

下面是我的 NLog 配置。

在 VS 中调试时,我得到了我期望的日志,但是当我在 VS 之外构建和运行程序时,我看不到任何日志。

有什么想法吗?

<?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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="true"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

  <!-- optional, add some variables
  https://github.com/nlog/NLog/wiki/Configuration-file#variables
  -->
  <variable name="myvar" value="myvalue"/>

  <!--
  See https://github.com/nlog/nlog/wiki/Configuration-file
  for information on customizing logging rules and outputs.
   -->
  <targets>

    <!--
    add your targets here
    See https://github.com/nlog/NLog/wiki/Targets for possible targets.
    See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
    -->

    <!--Write events to a file with the date in the filename.-->
    <target xsi:type="ColoredConsole" name="ColoredConsole" useDefaultRowHighlightingRules="true"
            layout="${message}" />

    <target xsi:type="File" name="ConsilioDeployTool_CLI_ErrorLog" fileName="${basedir}/logs/ConsilioDeployTool_CLI_ErrorLog_${shortdate}.log">
      <layout xsi:type="CsvLayout" delimiter="Pipe" withHeader="true">
        <column name="level" layout="${level:upperCase=true}"/>
        <column name="callsite" layout="${callsite:includeSourcePath=true}" />
        <column name="stacktrace" layout="${stacktrace:topFrames=10}" />
        <column name="exception" layout="${exception:format=ToString}"/>
        <column name="logger" layout="${logger:shortName=false}"/>
        <column name="message" layout="${message}" />
      </layout>
    </target>

  </targets>

  <rules>
    <!-- add your logging rules here -->

    <!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace)  to "f" -->
    <logger name="*" level="Info" writeTo="ColoredConsole" />
    <!--<logger name="*" level="Error" writeTo="ConsilioDeployTool_CLI_ErrorLog" />-->
    <logger name="*" level="Error" writeTo="ConsilioDeployTool_CLI_ErrorLog" />

  </rules>
</nlog>

【问题讨论】:

    标签: nlog


    【解决方案1】:

    确保用户 IIS_IUSRS 对站点文件夹具有写入权限

    您可以通过执行以下操作来分配写入权限:

    • 在 Windows 资源管理器中右键单击站点文件夹
    • 选择属性
    • 点击安全标签
    • 点击编辑...
    • 组或用户名:下,选择IIS_IUSRS
    • IIS_IUSRS 的权限下,点击写入复选框以允许用户写入站点文件夹
    • 单击应用,然后再次单击确定确定关闭“属性”窗口

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 1970-01-01
      • 2018-03-24
      • 2017-05-22
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 2016-05-02
      相关资源
      最近更新 更多