开发者

log4net error presentation

How to catch an error form log4net?

I have a program with log4net. The log4net is set a MySql server as repository. If it fail to connect to the MySql server, it will print many technical statements to con开发者_JAVA技巧sole but I don't want to show them. Therefore, I want to catch the error and show "Fail to connect to the MySql" only.


log4net does not throw exceptions. Rather it writes all exceptions to error log internally with

EventLog.WriteEntry("ErrorHandler","Error: " + ex.Message, EventLogEntryType.Error);

So all you need is to read eventlog entries fit for your purposes.


Well one short simple workaround is that you can try connecting to mysql using the same connection string before calling the log4net.Configure() function and check if the connection is possible.

OR

simply follow what this email says if you want to ensure connectivity at all times i.e. create your own exceptionHandler Email

Email is very very old but i dont think such implementation is changed even in the latest version.

just my 2cents :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜