What is the best way to write event log entries?

后端 未结 6 1188
盖世英雄少女心
盖世英雄少女心 2020-12-08 08:35

I recently had a problem during the deployment of a windows service. Four computers did not cause any problems, but on the fifth any attempt to start the service failed due

6条回答
  •  误落风尘
    2020-12-08 08:59

    System.Diagnostics.EventLog log = 
        new System.Diagnostics.EventLog("YourLogNameHere");
    log.ModifyOverflowPolicy(
        System.Diagnostics.OverflowAction.OverwriteAsNeeded, 0);
    

    This should fix your overflow problem. The event log is generally extremely reliable, once it's configured correctly. When using the event log, I used to add a quick emergency backup logger that simply wrote to a text file (this takes about 5 minutes to write). It never got called.

提交回复
热议问题