请求追踪

本文示例源码: https://github.com/liangshiw/LogDashboard/tree/master/samples/RequestTracking

各个日志组件都实现了 TraceIdentifier ,它是单次请求内唯一标识。LogDashboard使用它实现请求追踪功能

示例

在快速开始中的项目中,使用以下配置覆盖 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="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<variable name="myvar" value="myvalue"/>
<targets>
<target xsi:type="file" name="File" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\r\n} || ${aspnet-traceidentifier} ||end" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>

RequestTraceLogModel

Logdashboard预构建了RequestTraceLogModel 请求追踪日志模型,它继承自IRequestTraceLogModel 接口,也可以自行实现该接口

在注册服务时使用RequestTraceLogModel 做为自定义日志模型添加到服务中

services.AddLogDashboard(opt =>
{
opt.CustomLogModel<RequestTraceLogModel>();
});

运行项目导航到/logdashboard

enjoy