2007年5月11日星期五

c#写系统日志(http://www.113317.com/blog/article.asp?id=508)

(任何引用请注明:转载于美人山下http://beautyhill.blogspot.com)
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Log
{
class LogWirter
{
///


/// 事件源名称
///

private string eventSourceName;
EventLogEntryType eventLogType;
public LogWirter()
{
eventSourceName = "test";
eventLogType = EventLogEntryType.Error;
}

///
/// 消息事件源名称
///

public string EventSourceName
{
set { eventSourceName = value; }
}

///
/// 消息事件类型
///

public EventLogEntryType EventLogType
{
set { eventLogType = value; }
}

///
/// 写入系统日志
///

/// 事件内容
public void LogEvent(string message)
{
if (!EventLog.SourceExists(eventSourceName))
{
EventLog.CreateEventSource(eventSourceName, "Application");
}
EventLog.WriteEntry(eventSourceName, message, EventLogEntryType.Error);
}
}
}

没有评论: