写入日志小技巧

 EventLog log =  new EventLog( " Wodongni.Com ");
             //   首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定s
             if (!EventLog.SourceExists( " New Application1 "))
                EventLog.CreateEventSource( " New Application1 "" Wodongni.Com ");
             try
            {
                log.Source =  " New Applications1 ";
                log.WriteEntry( " 处理信息1 ", EventLogEntryType.Information);
                log.WriteEntry( " 处理信息2 ", EventLogEntryType.Information);
                 throw  new System.IO.FileNotFoundException( " readme.txt文件未找到 ");
            }
             catch (System.IO.FileNotFoundException exception)
            {
                log.WriteEntry(exception.Message, EventLogEntryType.Error);
            }

 

 

http://www.cnblogs.com/nokiaguy/archive/2009/02/26/1398708.html

你可能感兴趣的:(小技巧)