https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2
https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-3
参考配置
<?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_Data\Logs\nlogs.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的面板上看到各种日志和图表了。
总结
到此这篇关于使用Seq搭建免费的日志服务的文章就介绍到这了,更多相关Seq搭建日志服务内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!