/// <summary>
/// 把错误信息写入windows应用程序日志
/// </summary>
/// <param name="message">出错信息</param>
public static void Log(string message)
{
string EVENT_LOG_SOURCE = ".NET PetShop"; //来源标题
EventLog m_eventLog = null;
// make sure we have an event log
if (!(EventLog.SourceExists(EVENT_LOG_SOURCE))) //该日志不存在新建日志
{
EventLog.CreateEventSource(EVENT_LOG_SOURCE, "Application");
}
if (m_eventLog == null) {
m_eventLog = new EventLog("Application");//日志名称
m_eventLog.Source = EVENT_LOG_SOURCE;//日志来源
}
// log the message
m_eventLog.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error);//写入
代码摘自:PetShop
不过此方法一般现在很少使用,我们完全可以把错误信息写入到一个文件里,如文本文件
不过有没有用,先备份,说不定下次有用也说不定.^_^