日誌框架Nlog之非同步記錄

2022-07-01 05:33:10 字數 2024 閱讀 4050

日誌功能本來是一件非常好的事情,能幫助我們分析和解決很多問題。但是,如果讓日誌影響到效能,這就需要權衡一下了。沒關係,本篇部落格咱們不僅來解決這個問題,咱們更要眼見為實,帶圖帶真相讓你用的明明白白。

日誌實現非同步功能

其實呢就一句話。。

配置檔案targets中配置async="true"即為非同步。預設或寫false都為同步。

例如:

"

" xmlns:xsi="

" throwexceptions="

true

">

async="

true

">

"jsonfile

" xsi:type="

file

" filename="

$/logs/$/$.json

" archivefilename="

$/logs/$/log..json

" archivenumbering="

dateandsequence

" archiveabovesize="

10483760

" archivedateformat="

yyyymmdd

" encoding="

utf-8

">

"jsonlayout

">

"time

" layout="

$"/>

"machine

" layout="

$"/>

"level

" layout="

$"/>

"message

" layout="

$"/>

"warningfile

" xsi:type="

file

" filename="

$/warn/log.text

" archivefilename="

$/$/$/log..json

" archivenumbering="

dateandsequence

" archiveabovesize="

10483760

" archivedateformat="

yyyymmdd

">

"jsonlayout

">

"time

" layout="

$"/>

"machine

" layout="

$"/>

"logger

" layout="

$"/>

"level

" layout="

$"/>

"message

" layout="

$"/>

"fatalfile

" xsi:type="

file

" filename="

$/fatal/log.text

" archivefilename="

log..json

" archivenumbering="

dateandsequence

" archiveabovesize="

10483760

" archivedateformat="

yyyymmdd

">

"jsonlayout

">

"time

" layout="

$"/>

"machine

" layout="

$"/>

"logger

" layout="

$"/>

"message

" layout="

$"/>

"*" minlevel="

debug

" maxlevel="

error

" writeto="

jsonfile

"/>

C 日誌框架NLog

nutgue中搜尋 nlog 進行安裝,它會提示你根據你.net版本選擇相應的版本 安裝後會自動在專案目錄項建立nlog.config檔案,這是人家的配置檔案,照搬 封裝乙個工具類以操控nlog,如果後續專案使用其他的日誌框架,直接改此工具類就好了 using system using system...

Nlog 日誌框架簡單教程

安裝 nuget獲取 配置尋找 會自動尋找在應用程式目錄下的nlog.config 大小寫敏感 如何配置config xmlns xsi xsi schemalocation nlog.xsd autoreload true throwexceptions false internallogleve...

日誌框架NLog之將日誌傳送到郵件

nlog可以將日誌輸出到不同的媒介上,郵件是其中乙個,通過郵件可以讓我們第一時間收到資訊。使用smtp協議通過電子郵件傳送日誌訊息。與fallbackgroup target很好地結合在一起,以建立具有多個smtp主機的後備。smtpserver 用於傳送的smtp伺服器。需要布局。smtpport...