如標題,這個夠犀利了,主要是設定target。
電子郵件
<!-- 寄送 電子郵件 的設定 -->
<target name="email" xsi:type="Mail"
smtpServer="192.168.1.1"
smtpPort="25"
smtpAuthentication="Basic"
smtpUserName="帳號"
smtpPassword="密碼"
enableSsl="false"
from="hello@abc.com.tw"
to="admin@abc.com.tw"
html="true"
encoding="UTF-8"
addNewLines="true"
subject="不好了!!!${machinename} 於 ${shortdate} ${time} 產生 ${level} 等級的錯誤。"
header="##########################################################################"
body="${newline}
時間:${longdate} ${newline}${newline}
等級:${level:uppercase=true} ${newline}${newline}
紀錄者:${logger} ${newline}${newline}
來源:${callsite:className=true} ${newline}${newline}
Exception類:${exception:format=type} ${newline}${newline}
錯誤訊息:${message} ${newline}${newline}"
footer="##########################################################################"
/>
newline對html而言是沒有作用的,會擠成一坨,可以在加入以下(讓config使用<br>換行)
<br>
事件檢視器
<!-- 輸出至 Windows 事件日誌 -->
<target name="eventLog" xsi:type="EventLog"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
source="Huanlin Web Services"
log="Application" />
最後就是觸發事件的等級要設定一下
<logger name="*" minlevel="Warn" writeTo="eventLog" />
<logger name="*" minlevel="Fatal" writeTo="mail" />
參考來源:
https://www.huanlintalk.com/2013/08/nlog-configuration-example.html