日期:2014-05-18 浏览次数:20902 次
/// <summary> /// 建立系统事件日志 /// </summary> /// <param name="LogSource">事件源</param> /// <param name="LogName">事件名称</param> /// <returns>是否成功</returns> public bool CreateEventLog(string LogSource, string LogName) { bool rel = false; if (!EventLog.SourceExists(LogName)) { EventLog.CreateEventSource(LogSource, LogName); rel = true; } return rel; } /// <summary> /// 写入事件日志 /// </summary> /// <param name="LogSource">事件源</param> /// <param name="LogName">事件名称</param> /// <param name="Log">事件内容</param> public void RecordSysLog(string LogSource, string LogName, string Log) { if (!EventLog.SourceExists(LogSource)) { if (this.CreateEventLog(LogSource,LogName)) { EventLog elog1 = new EventLog(LogName); elog1.WriteEntry(Log); elog1.Close(); } } } /// <summary> /// 写文件 /// </summary> /// <param name="Path">文件路径</param> /// <param name="Strings">写入内容</param> public static void WriteFile(string Path, string Strings) { if (!File.Exists(Path)) { FileStream fs = File.Create(Path); fs.Close(); fs.Dispose(); } StreamWriter sw = new StreamWriter(Path, true, Encoding.UTF8); sw.WriteLine(Strings); sw.Close(); sw.Dispose(); } /// <summary> /// 写入文件,包括时间 /// </summary> /// <param name="Path">文件路径</param> /// <param name="Strings">文件内容</param> /// <param name="dt">写入时间</param> public static void WriteFile(string Path, string Strings, DateTime dt) { if (!File.Exists(Path)) { FileStream fs = File.Create(Path); fs.Close(); fs.Dispose(); } StreamWriter sw2 = new StreamWriter(Path,true,Encoding.UTF8); sw2.WriteLine(Strings + "|"