What is the best way to write event log entries?

后端 未结 6 1166
盖世英雄少女心
盖世英雄少女心 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:58

    Can't you just use the default event-log mechanism that the ServiceBase class already provides? If your service doesn't start that will automatically write an entry to the event log stating so (with stacktrace).

    Apart from that, and concerning the comments about log4net (or any other best-effort like logging-system), I think it really depends what you are trying to achieve.

    In your example using log4net (or the builtin support for eventlogging of ServiceBase) is most likely OK.

    However, there are situations where even the fact that an error occurred and that that fact could not be logged somewhere is a problem. For example, assume an authentication or authorization system. If you cannot successfully and reliably log that a, say, password authentication failed because of wrong credentials, you're maybe not allowed to continue (same so BTW if you the password authentication would have been successful).

    So, sometimes you need to know when a logging attempt failed and handle that by itself. There are limits to this of course (chicken-egg-problem), and what you do is highly specific to the particular application or scenario.

提交回复
热议问题