ch7_08.cs
来自「《c#技术内幕代码》」· CS 代码 · 共 60 行
CS
60 行
using System;
using System.Diagnostics;
class CH7_8
{
public static void WriteLog()
{
string source = "EventSource";
string log = "CH7_8.LOG";
// Create a new Event Log
EventLog el = new EventLog();
// See if it exists.
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source,log);
}
el.Source = source;
String message = "Starting Up";
el.WriteEntry(message, EventLogEntryType.Information);
message = "Processing";
el.WriteEntry(message, EventLogEntryType.Information);
message = "Shutting down";
el.WriteEntry(message, EventLogEntryType.Information);
}
public static void ReadLog()
{
string source = "EventSource";
// Create a new Event Log
EventLog el = new EventLog();
// See if it exists.
if (!EventLog.SourceExists(source))
{
Console.WriteLine("Event Log does not exist!");
return;
}
el.Source = source;
foreach (EventLogEntry entry in el.Entries) {
Console.WriteLine("\tEntry: " + entry.Message);
}
}
public static void DeleteLog()
{
string log = "CH7_8.LOG";
EventLog.Delete( log );
}
public static void Main()
{
WriteLog();
ReadLog();
DeleteLog();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?