使用Seq搭建免费的日志服务的方法
https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2 参考配置 <?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="App_DataLogsnlogs.log" throwExceptions="true"> <!-- 定义日志输出的根目录为web目录的上级目录 --> <variable value="${basedir}/App_Data/logs"/> <extensions> <add assembly="NLog.Web.AspNetCore"/> <add assembly="NLog.Targets.Seq"/> </extensions> <targets async="true"> <default-target-parameters type="File" archiveAboveSize="50485760" maxArchiveFiles="50" archiveNumbering="Rolling" keepFileOpen="false" layout="${date:format=HH:mm:ss:ffff}:[${level}] ${callsite} ${onexception:${exception:format=tostring} ${newline}${stacktrace}${newline}"/> <!--屏幕彩色打印消息--> <target xsi:type="ColoredConsole" layout="${date:format=HH:mm:ss:ffff}:[${level}] ${message}"/> <!--默认日志--> <target xsi:type="File" fileName="${logdir}/${level}/${shortdate}.log" layout="${date:format=HH:mm:ss:ffff}: ${message} ${onexception:${exception:format=tostring} ${newline}${stacktrace}${newline}" /> <target xsi:type="File" fileName="${logdir}/${level}/${shortdate}.log" layout="${date:format=HH:mm:ss:ffff}: ${logger}${newline}${message} ${onexception:${exception:format=tostring} ${newline}${stacktrace}${newline}" /> <target xsi:type="BufferingWrapper" bufferSize="1000" flushTimeout="2000"> <target xsi:type="Seq" serverUrl="http://devlogs.yourdomain.com" apiKey="DRkZrdeDMZIXY0gzZGXB"> <property value="${threadid}" as="number" /> <property value="${machinename}" /> <property value="Development" /> <!--https://github.com/NLog/NLog/wiki/Logger-Layout-Renderer--> <property value="${logger}" /> <!--https://github.com/NLog/NLog/wiki/AspNet-Request-IP-Layout-Renderer--> <property value="${aspnet-request-ip}" /> <!--https://github.com/NLog/NLog/wiki/AspNetRequest-Url-Layout-Renderer--> <property value="${aspnet-request-url:IncludeHost=true:IncludePort=true:IncludeQueryString=true:IncludeScheme=true}" /> <property value="${aspnet-response-statuscode}" /> </target> </target> </targets> <rules> <logger minlevel="Trace" writeTo="seq" /> <logger levels="Trace,Debug,Info" writeTo="console,defaultLog" /> <logger minlevel="Warn" writeTo="console,warnLog" /> </rules> </nlog> 集成之后,我们就可以非常方便的在Seq的面板上看到各种日志和图表了。 (编辑:济南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |