首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急C#的日志文件如何写

2012-02-14 
急^_____________C#的日志文件怎么写?C#的日志文件怎么写?[解决办法]6.将错误记录保存到Windows系统日志中

急^_____________C#的日志文件怎么写?
C#的日志文件怎么写?

[解决办法]
6.将错误记录保存到Windows系统日志中
public class LogError
{
private const string c_EventSource = "love ";
private const string c_LogName = "Application ";

public static void Write(string errorMessage)
{
try
{
//判断名称为 "love " 的事件源是否存在
if (!EventLog.SourceExists(c_EventSource))
{
//如果不存在就试图创建
EventLog.CreateEventSource(c_EventSource, c_LogName);
}
// 已存在,写错误消息到日志
EventLog msg = new EventLog(c_LogName);
msg.Source = c_EventSource;
msg.WriteEntry(errorMessage, EventLogEntryType.Error);
}
catch
{ }
}
}

热点排行