NLog寄送電子郵件與紀錄事件檢視器

如標題,這個夠犀利了,主要是設定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>換行)

&lt;br&gt; 

事件檢視器

<!-- 輸出至 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

More From Forest Beat

冬の前田森林公園のフリ

在Linux中列出目錄的空間使用大小

列出檔案大小的指令是ls,但是這個指令列出的目錄大小是固定的,又不能自動加總,所以想要知道/home/下各個使用者用了多少檔案空間,那可以參考以下指令
技術
0
minutes
高層ビルのフリー写真素材

Windows 10中的小算盤不見了?

如題小算盤不見了怎麼辦?其實很簡單,搜尋商店,然後輸入關鍵字,安裝一下就可以~~~
技術
0
minutes
桜のフリ

Top 20 Best Programming Languages To Learn in 2024

IT小菜雞必需掌握一種以上的程式語言,因為程式語言是實現軟體解決方案的工具。
技術
0
minutes
サクラのフリ

快速了解MVC、MVP、MVVM、MVI架構的演進

MVC、MVP、MVVM、MVI 都是軟體架構模式,用來組織和管理程式碼,提高程式碼的可讀性、可維護性和可擴展性。
技術
0
minutes
spot_imgspot_img