繁体   English   中英

ASP.Net Core 记录没有详细信息的 Kestrel 错误

[英]ASP.Net Core logs Kestrel errors without details

我有一个带有 API 控制器和 SignalR 的 ASP.NET Core 3.1 Web 应用程序。 日志框架是 NLog。 我在生产服务器上收到一些奇怪的错误:

ERROR|Microsoft.AspNetCore.Server.Kestrel|Connection id "...", Request id "...": An unhandled exception was thrown by the application. Object reference not set to an instance of an object.

他们没有任何细节。 我的日志参数是:

  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
  }

我的 NLog 配置:

<?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="Warn"
      internalLogFile="...">


  <!-- the targets to write to -->
  <targets>
    <!-- write logs to file  -->
    <target xsi:type="File" name="allfile" fileName="..."
            layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" />

    <!-- another file log, only own logs. Uses some ASP.NET core renderers -->
    <target xsi:type="File" name="ownFile-web" fileName="..."
            layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

    <!-- write to the void aka just remove -->
    <target xsi:type="Null" name="blackhole" />
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Warn" writeTo="allfile" />

    <!--Skip Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" minlevel="info" writeTo="blackhole" final="true" />
    <logger name="*" minlevel="Warn" writeTo="ownFile-web" />
  </rules>
</nlog>

有没有办法获得有关这些错误的更多信息? 我应该实现一些异常过滤器吗? 谢谢!

我已经找到了我自己问题的答案。 我需要使用“${exception:format=tostring}”格式来获取 NLog 日志中的异常详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM