1.?專門創建Source的Log?
創建了Source,log顯示在? Event viewer/Applications and Services logs/ 自定義Source 中,待遇比較高,專門顯示的。
創建Source需要管理員身份,否則Crash。
如果已經打開了 Computer Management,請關閉然后再打開,才能看到剛才創建的Source。
代碼如下
// Create the source, if it does not already exist.if (!EventLog.SourceExists(logSource)){EventLog.CreateEventSource(logSource, logName);}EventLog.WriteEntry(tbSourceName.Text, tbMessage.Text, type, getValue(tbEventID.Text), getShortValue(tbCategory.Text));
Source 創建后,寫入日志就不需要管理員身份了。
實際使用場合,安裝軟件的時候,創建一下Source。
2. 不創建Source,代碼就一句
?EventLog.WriteEntry(tbSourceName.Text, tbMessage.Text, type, getValue(tbEventID.Text), getShortValue(tbCategory.Text));
這個每次運行都需要管理員身份,比較扯淡。
日志顯示在 Event Viewers/Windows Logs/Application 中.
?
3. 每一條log,都有 General和Details 兩個信息,算是詳細,但貌似又沒啥用。
?
總之,不太爽。
寫的也亂,見諒!
?Demo
?