簡體   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