使用 NLog 将日志传送到 Logz.io 失败
Shipping logs to Logz.io with NLog fails
我只是想将一些错误日志从我的 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"
时,我可以在我的本地磁盘上找到一个带有 "Something bad happens" 的日志文件,所以一切都很好。
但是,当我 writeTo="logzio"
时,我的 LogzIo Web 界面上什么也没有出现,没有日志传送到那里。
我错过了什么?
我遇到了同样的问题,结果发现在我发布的应用程序中,logzio dll 丢失了。我添加了它们并解决了问题。
检查您的 bin 文件夹中是否缺少这些文件:
Logzio.DotNet.NLog.dll
Logzio.DotNet.Core.dll
在找到解决方法后回答我自己的问题。
实际上,我的整个项目都使用 HTTPS。
在内部 Nlog 日志中,我有这个错误
Error : System.Net.WebException : The request was aborted: Could not create SSL/TLS secure channel
我刚刚在 Global.asax.cs
中 ApplicationStart
的开头添加了这行代码
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
经过几天对整个项目的测试,似乎并没有影响到项目的其他部分。
但是,请小心,因为它是全局设置
我只是想将一些错误日志从我的 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"
时,我可以在我的本地磁盘上找到一个带有 "Something bad happens" 的日志文件,所以一切都很好。
但是,当我 writeTo="logzio"
时,我的 LogzIo Web 界面上什么也没有出现,没有日志传送到那里。
我错过了什么?
我遇到了同样的问题,结果发现在我发布的应用程序中,logzio dll 丢失了。我添加了它们并解决了问题。
检查您的 bin 文件夹中是否缺少这些文件: Logzio.DotNet.NLog.dll Logzio.DotNet.Core.dll
在找到解决方法后回答我自己的问题。
实际上,我的整个项目都使用 HTTPS。 在内部 Nlog 日志中,我有这个错误
Error : System.Net.WebException : The request was aborted: Could not create SSL/TLS secure channel
我刚刚在 Global.asax.cs
ApplicationStart
的开头添加了这行代码
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
经过几天对整个项目的测试,似乎并没有影响到项目的其他部分。 但是,请小心,因为它是全局设置