[C#]写系统日志和写日志文件
事件日志: 使用EventLog 类,如: 下面的示例创建源 MySource(如果尚未存在),并在事件日志 MyNewLog 中写入一项。 using System; using System.Diagnostics; using System.Threading; class MySample{ public static void Main(){ // Create the source, if it does not already exist. if(!EventLog.SourceExists( "MySource ")){ EventLog.CreateEventSource( "MySource ", "MyNewLog "); Console.WriteLine( "CreatingEventSource "); } // Create an EventLog instance and assign its source. EventLog myLog = new EventLog(); myLog.Source = "MySource "; // Write an informational entry to the event log. myLog.WriteEntry( "Writing to event log. "); } } 文本文件: