【问题标题】:Shipping logs to Logz.io with NLog fails使用 NLog 将日志发送到 Logz.io 失败
【发布时间】:2018-12-03 13:09:54
【问题描述】:

我只是想将一些错误日志从我的 ASP.NET MVC 5 应用程序发送到 Logz.io

我正在使用 NLog 发送我的日志。
我已经安装了 NLog 和 NLog.Web 包

我有以下 nlog.config 文件:

<?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"
            throwExceptions="true"
            internalLogLevel="ERROR"
            internalLogFile="C:\Temp\nlog-internal.log">

  <extensions>
    <add assembly="Logzio.DotNet.NLog"/>
  </extensions>

  <targets async="true">
    <target name="file" type="File"
            fileName="<pathToFileName>"
            archiveFileName="<pathToArchiveFileName>"
            keepFileOpen="false"
            layout="<long layout patten>"/>

    <target name="logzio"
                    type="Logzio"
                    token="LRK......"
                    logzioType="nlog"
                    listenerUrl="https://listener.logz.io:8071"
                    bufferSize="1"
                    bufferTimeout="00:00:05"
                    retriesMaxAttempts="3"
                    retriesInterval="00:00:02"
                    debug="false" />
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="logzio" />
  </rules>
</nlog>

然后,我的每个 C# 控制器都有这一行:

private static Logger logger = LogManager.GetCurrentClassLogger();

然后我尝试使用类似的方式发送我的日志:

logger.Fatal("Something bad happens");

但是,当我在nlog.config 文件中writeTo="file" 时,我可以在我的本地磁盘上找到一个日志文件,上面写着“发生了一些糟糕的事情”,所以一切都很好。

但是,当我writeTo="logzio" 时,我的 LogzIo 网页界面上什么也没有显示,那里没有发送任何日志。

我错过了什么?

【问题讨论】:

  • 您是否尝试更改为internalLogLevel="Warn" 并查看internalLogFile
  • 我卸载/重新安装 LogzIo 包(我的包已经过时),当我在本地环境中 writeTo="file" 时,我现在有 3 次此错误(如 3 次 retriesMaxAttempts):Error : System.Net.WebException : The request was aborted: Could not create SSL/TLS secure channel。我正在调查,但感谢任何线索:)
  • 也许强制启用强加密:support.microsoft.com/help/4458166

标签: asp.net-mvc logging nlog error-logging logz.io


【解决方案1】:

在找到解决方法后回答我自己的问题。

实际上,我的整个项目都使用 HTTPS。 在内部 Nlog 日志中,我遇到了这个错误

错误:System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道

我刚刚在ApplicationStart 开头的Global.asax.cs 中添加了这行代码

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

在对整个项目进行了几天的测试后,它似乎不会影响项目的其他部分。 但是,请小心,因为它是全局设置

【讨论】:

  • 我也有同样的问题,你是怎么看到nlog内部错误的?
【解决方案2】:

我遇到了同样的问题,结果发现在我发布的应用程序中缺少 logzio dll。我添加了它们,它解决了问题。

检查您的 bin 文件夹中是否缺少这些文件: Logzio.DotNet.NLog.dll Logzio.DotNet.Core.dll

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2014-10-04
    • 2020-04-03
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多