------------------------------------------------------------------------
{
EventLog m_enentLog=null;
行 14: if(!( EventLog.SourceExists(ERROR_LOG_SOURCE)))
行 15: {
行 16: EventLog.CreateEventSource(ERROR_LOG_SOURCE, "Application");
------------------------------------------------------------------------
原来PetShop中的错误是要写到操作系统日志中的,在Erro.cs中:
public
class
Error
{ //例如我的应用程序的名称是:comeday
const string ERROR_LOG_SOURCE="comeday";
public static void Log(string message)
{
EventLog m_enentLog=null;
if(!(EventLog.SourceExists(ERROR_LOG_SOURCE)))
{
EventLog.CreateEventSource(ERROR_LOG_SOURCE, "Application");
}
if(m_enentLog ==null)
{
m_enentLog=new EventLog("Application");
m_enentLog.Source=ERROR_LOG_SOURCE;
}
m_enentLog.WriteEntry(message,System.Diagnostics.EventLogEntryType.Error);
}
}
{ //例如我的应用程序的名称是:comeday
const string ERROR_LOG_SOURCE="comeday";
public static void Log(string message)
{
EventLog m_enentLog=null;
if(!(EventLog.SourceExists(ERROR_LOG_SOURCE)))
{
EventLog.CreateEventSource(ERROR_LOG_SOURCE, "Application");
}
if(m_enentLog ==null)
{
m_enentLog=new EventLog("Application");
m_enentLog.Source=ERROR_LOG_SOURCE;
}
m_enentLog.WriteEntry(message,System.Diagnostics.EventLogEntryType.Error);
}
}
在注册表
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
加入:项“ comeday”(你的应用程序名称,我的是comeday)就OK了。