【问题标题】:Why is my NLog configuration not working on my server machine?为什么我的 NLog 配置在我的服务器机器上不起作用?
【发布时间】:2014-01-23 14:55:36
【问题描述】:

我正在使用 ServiceStack 框架和 NLog 进行日志记录。我可以很好地登录我的本地机器。但是在服务器上,它没有。我检查了Nlog.configbin目录和整个目录,包括bin目录上面的目录有写权限。

下面是配置文件的sn-p:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets async="true">
        <target xsi:type="File" name="file" fileName="${basedir}\logs\${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
        <target xsi:type="Debugger" name="debug"
            header="===== ${date:format=ddd, dd MMM yyyy} ${time} ====="
            layout="${level} | ${logger} | ${message} | ${onexception:${exception:format=tostring} | ${stacktrace}}"
            footer="===== end of session ===== ${newline}"
        />
    </targets>
    <rules>
        <logger name="*" minlevel="Trace" writeTo="file,debug" />    
    </rules>
</nlog>

可能是什么问题?

【问题讨论】:

    标签: c# .net web-services servicestack nlog


    【解决方案1】:

    您是否尝试过将路径更改为您知道的东西?

    fileName="${basedir}\logs\${shortdate}.log" 改为fileName="c:\logs\${shortdate}.log" 之类的?

    Web 应用程序中 NLog 的 basedir 变量不在 bin 文件夹中运行。我想你会在里面找到日志文件

    %SystemRoot%\Microsoft.NET\Framework\versionNumber\Temporary ASP.NET Files
    

    如果它是 ASP.NET 应用程序。

    【讨论】:

    • 我恐怕无法访问 c: 驱动器,因为它是外部共享托管服务器
    • 我建议使用 C:\,但您可以使用您有权访问的任何其他文件夹路径,并且您的代码对 bin 文件夹具有写入权限并不是一个很好的做法。
    【解决方案2】:

    虽然我不知道您的服务器环境和配置具体出了什么问题,但我一直发现检查以下内容很有帮助:

    1. 确保您确切知道日志的目录是什么(由@PauloCorreia 建议)。
    2. 确保该目录确实存在。
    3. 确保 IIS 工作进程具有能够写入该目录的正确权限。

    FWIW,根据我的经验,这通常是权限问题。

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      相关资源
      最近更新 更多