使用logdashboard進行可視化的日誌追蹤

本文源碼在Github能夠找到下載html

LogDashboard

若是你還不瞭解LogDashboard請看這裏。 LogDashboard 1.1版本支持請求追蹤,雖然目前版本尚未發佈。不過這個功能能夠先睹爲快git

效果圖github

<img src="https://img2018.cnblogs.com/blog/832799/201901/832799-20190117173526959-1881709032.gif" referrerpolicy="no-referrer">shell

下載項目

首先咱們能夠在 https://github.com/liangshiw/LogDashboard/tree/master/samples/RequestTracking 裏下載源碼,而且使用VisualStudio打開項目,目錄結構以下數據庫

<img src="https://img2018.cnblogs.com/blog/832799/201901/832799-20190117173749277-394501522.jpg" referrerpolicy="no-referrer">ide

配置說明

咱們將 RequestTracking 設置爲啓動項目, 打開startup.cs文件能夠看到LogDashboard服務與中間件已經配置成功.spa

在添加服務時咱們添加了自定義的LogModel RequestTraceLogModel 事實上RequestTraceLogModel是LogDashboard預構建的日誌模型, 除此以外LogDashboard提供了接口IRequestTraceLogModel以便開發者自定義本身的追蹤模型。日誌

咱們把目光轉到Config上面,這個示例使用了Nlog日誌組件,Nlog提供了 ${aspnet-traceidentifier} 作爲請求標識, log4net也一樣能夠實現code

<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" />

在運行時咱們依次輸出瞭如下日誌orm

<img src="https://img2018.cnblogs.com/blog/832799/201901/832799-20190117172628099-1963841023.jpg" referrerpolicy="no-referrer">

啓動項目

如今啓動項目並導航到 /LogDashboard , 這時會看到日誌面板的首頁面,這時點擊詳情並找到請求追蹤選項卡就能夠達到文章開頭動態圖片演示的效果

<img src="https://img2018.cnblogs.com/blog/832799/201901/832799-20190117174118944-549362057.png" referrerpolicy="no-referrer">

數據庫源

剛纔看到的是文件源示例, https://github.com/liangshiw/LogDashboard/tree/master/samples/DatabaseSource 這個是數據庫源的示例,一樣支持請求追蹤。操做方法與上面相似

More

歡迎入羣交流

<img src="https://user-images.githubusercontent.com/16813853/51227366-df111580-198e-11e9-9e0c-f7b077e63fe7.png" referrerpolicy="no-referrer">

原文出處:https://www.cnblogs.com/LiangSW/p/10283574.html

相關文章
相關標籤/搜索