Table of Contents

Class MyLog

Namespace
ZapLib
Assembly
ZapLib.dll

紀錄事件與日誌工具

public class MyLog
Inheritance
MyLog
Inherited Members

Constructors

MyLog()

建構子,可指定 log 檔案名稱預設將以今天 yyyyMMdd 形式命名,也可自行指定其他日期,以利讀取

public MyLog()

MyLog(string)

建構子,可指定 log 檔案名稱,預設將以今天 yyyyMMdd 形式命名,也可自行指定其他日期,以利讀取

public MyLog(string Name)

Parameters

Name string

日誌檔名,預設今天 yyyyMMdd

Properties

LastWritePath

最後一次 Log 檔案寫入位置

public string LastWritePath { get; set; }

Property Value

string

Name

日誌名稱,預設以 yyyy-mm-dd 進行命名,每天只會產生一個檔案

public string Name { get; set; }

Property Value

string

PageSize

讀取 log 的批次大小,預設 1mb

public int PageSize { get; set; }

Property Value

int

Path

日誌存放路徑

public string Path { get; set; }

Property Value

string

SilentMode

使否啟用安靜模式,預設為 NULL,啟用後本類別將不再寫檔

public string SilentMode { get; set; }

Property Value

string

Methods

Event(Exception, EventLogEntryType, string, string, int)

將例外物件記錄到 Windows 事件檢視器中

public void Event(Exception ex, EventLogEntryType type = EventLogEntryType.Error, string ProjectName = "", string CodePath = "", int LineNumber = 0)

Parameters

ex Exception

例外物件

type EventLogEntryType

事件類型,預設為 Error

ProjectName string

請勿設定

CodePath string

請勿設定

LineNumber int

請勿設定

Event(string, EventLogEntryType, string, string, int)

將指定訊息記錄到 Windows 事件檢視器中

public void Event(string msg, EventLogEntryType type = EventLogEntryType.Information, string ProjectName = "", string CodePath = "", int LineNumber = 0)

Parameters

msg string

指定訊息

type EventLogEntryType

事件類型,預設為 Information

ProjectName string

請勿設定

CodePath string

請勿設定

LineNumber int

請勿設定

Read(int)

使用翻頁的機制,從後往前讀取指定的 log 檔案

public ModelLog Read(int page = 1)

Parameters

page int

頁數,預設第 1 頁

Returns

ModelLog

Log 讀取結果資料模型

Write(string)

將訊息寫入實體日誌檔案,優先採用指定路徑,第二採用 Config 設定中的 MyLog,第三採用 Config 設定中的 Storage

public void Write(string msg)

Parameters

msg string

訊息