using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace Utils
{
/// <summary>
/// <para> </para>
/// 常用工具類——系統日志類
/// <para> ---------------------------------------------------</para>
/// <para> WriteEventLog:寫入系統日志(2個方法重載)</para>
/// <para> DelEventName:刪除日志事件源分類</para>
/// </summary>
public class EventLogHelper
{
#region 寫入系統日志
/// <summary>
/// 寫入系統日志
/// </summary>
/// <param name="EventName">事件源名稱</param>
/// <param name="LogStr">日志內容</param>
public static void WriteEventLog(string EventName, string LogStr)
{
try
{
if (!EventLog.SourceExists(EventName))
{
EventLog.CreateEventSource(EventName, EventName);
}
EventLog.WriteEntry(EventName, LogStr);
}
catch (Exception)
{
}
}
/// <summary>
/// 寫入系統日志
/// </summary>
/// <param name="EventName">事件源名稱</param>
/// <param name="LogType">日志類型</param>
/// <param name="LogStr">日志內容</param>
public static void WriteEventLog(string EventName, string LogStr, EventLogEntryType LogType)
{
try
{
if (!EventLog.SourceExists(EventName))
{
EventLog.CreateEventSource(EventName, EventName);
}
EventLog.WriteEntry(EventName, LogStr, LogType);
}
catch (Exception)
{
}
}
#endregion
#region 刪除日志事件源分類
/// <summary>
/// 刪除日志事件源分類
/// </summary>
/// <param name="EventName">事件源名</param>
/// <returns></returns>
public static bool DelEventName(string EventName)
{
bool flag = false;
try
{
if (EventLog.SourceExists(EventName))
{
EventLog.DeleteEventSource(EventName,".");
flag = true;
}
}
catch (Exception)
{
}
return flag;
}
#endregion
}
}