establish log file in system

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Diagnostics;
 7 
 8 
 9 namespace ConsoleApplication1
10 {
11     class Program
12     {
13         static void Main(string[] args)
14         {
15             EventLog log = new EventLog();
16             try
17             {
18                 log.Source = "系统2";
19                 log.WriteEntry("deal with message of one", EventLogEntryType.Information);
20                 log.WriteEntry("deal with message of two",EventLogEntryType.Information);
21                 throw new System.IO.FileNotFoundException("readme.txt文件未找到");
22             }
23             catch(System.IO.FileNotFoundException exception)
24             {
25                 log.WriteEntry("deal with message two",EventLogEntryType.Error);  
26             }
27 
28         }
29     }
30 }

 

posted on 2018-09-21 08:22  fortwater  阅读(121)  评论(0编辑  收藏  举报

导航