2012年10月29日 星期一

VB.NET Log 如何的寫入

而app.config中有定義一個FileLog,內定會把log產生到檔案中,如果我們unmark EventLog的部份,那麼它


還會產生log於Windows的EventLog之中,所以非好用。而 app.config中DefaultSwitch 的value內定是Information

更改它之後(像我改它成Error),可以讓程式變成只記錄Error與Critial。

With My.Application.Log.DefaultFileLogWriter

.BaseFileName = "cwwT" '設log的檔名開頭

.CustomLocation = "c:\" '設log存放之dir

.AutoFlush = True

.IncludeHostName = True

.LogFileCreationSchedule = Logging.LogFileCreationScheduleOption.Daily '設定一天一個檔

MsgBox(My.Application.Log.DefaultFileLogWriter.FullLogFileName) 'c:\cwwT-2009-09-25.log

My.Application.Log.WriteEntry("TestInfor", TraceEventType.Information, 10) '不會記錄

My.Application.Log.WriteEntry("TestError", TraceEventType.Error, 20)

End With

以下是app.config

type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

此表會顯示「記錄檔」在特定的 DefaultSwitch 設定下,將訊息寫入接聽程式所需的嚴重性層級


成員名稱 說明

Off 不允許任何事件通過。

Critical 只允許 Critical 事件通過。

Error 允許 Critical 和 Error 事件通過。

Warning 允許 Critical、Error 和 Warning 事件通過。

Information 允許 Critical、Error、Warning 和 Information 事件通過。

Verbose 允許 Critical、Error、Warning、Information 和 Verbose 事件通過。

ActivityTracing 允許 Stop、Start、Suspend、Transfer 和 Resume 事件通過。

All 允許所有事件通過。

沒有留言: