【问题标题】:ASP.Net Core logs Kestrel errors without detailsASP.Net Core 记录没有详细信息的 Kestrel 错误
【发布时间】:2020-04-03 04:25:40
【问题描述】:

我有一个带有 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>

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

【问题讨论】:

    标签: c# nlog asp.net-core-3.1


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 2019-03-23
      • 2014-10-26
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多