写入日志小技巧
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);
}
// 首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定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);
}
private static void WriteMsg(string msg) { string txtPath = System.AppDomain.CurrentDomain.BaseDirectory+"\\demo.txt"; StreamWriter sw = new StreamWriter(txtPath, true, System.Text.Encoding.Default); sw.WriteLine("time:"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sw.WriteLine(msg); sw.Close(); }
http://www.cnblogs.com/nokiaguy/archive/2009/02/26/1398708.html
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。