public class LogWriter
{
/// <summary>
/// 写入系统日志
/// </summary>
/// <param name="message">事件内容</param>
private static void LogEvent(EventLogEntryType eventLogType, string eventSourceName, string message)
{
if (!EventLog.SourceExists(eventSourceName))
{
EventLog.CreateEventSource(eventSourceName, "Application");
}
EventLog.WriteEntry(eventSourceName, message, eventLogType);
}
public static void LogErrorEvent(string eventSourceName, string message)
{
LogEvent(EventLogEntryType.Error, eventSourceName, message);
}
public static void LogWaringEvent(string eventSourceName, string message)
{
LogEvent(EventLogEntryType.Warning, eventSourceName, message);
}
}