2011-02-25 27 views
0

如何將錯誤從我的C#winforms程序寫入Windows事件?如何寫入Windows事件以及以後如何查看?

以及我以後怎麼看?

有沒有什麼工具可以看到它?

我可以得到任何示例代碼如何做到這一點?

在此先感謝

+0

控制面板+管理工具+事件查看器來查看事件。 EventLog的MSDN文檔有示例代碼。 – 2011-02-25 07:09:15

回答

0

使用日誌庫像log4net。有了這樣的庫,您可以配置幾個'appender',登錄到Windows事件日誌,文件,發送郵件等。在網上你可以找到很多例子。 (提示:log4net windows事件查看器)

0

下面是一個示例從MSDN:

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")) 
     { 
      //An event log source should not be created and immediately used. 
      //There is a latency time to enable the source, it should be created 
      //prior to executing the application that uses the source. 
      //Execute this sample a second time to use the new source. 
      EventLog.CreateEventSource("MySource", "MyNewLog"); 
      Console.WriteLine("CreatedEventSource"); 
      Console.WriteLine("Exiting, execute the application a second time to use the source."); 
      // The source is created. Exit the application to allow it to be registered. 
      return; 
     } 

     // 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."); 

    } 
} 
相關問題