Wonderful logger
-
I guess many of you have heard about log4j, log4net, log4cplus logging libraries. I'm going to show you the worst log appender I've ever seen. It shows message boxes!
class CustomLogAppender : FileAppender { protected override void Append(LoggingEvent loggingEvent) { base.Append(loggingEvent); if (loggingEvent.Level >= Level.Info) { if (Application.OpenForms != null && Application.OpenForms.Count > 0) { if (loggingEvent.Level == Level.Info) { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Exclamation); } else { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Error); } } } } }
Let's say you need to log 100 error messages. That means that potential user is going to click "OK" 100 times:mad:. Cool, isn't it? And if this logger occasionally gets into some ASP.NET application... :((
-
I guess many of you have heard about log4j, log4net, log4cplus logging libraries. I'm going to show you the worst log appender I've ever seen. It shows message boxes!
class CustomLogAppender : FileAppender { protected override void Append(LoggingEvent loggingEvent) { base.Append(loggingEvent); if (loggingEvent.Level >= Level.Info) { if (Application.OpenForms != null && Application.OpenForms.Count > 0) { if (loggingEvent.Level == Level.Info) { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Exclamation); } else { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Error); } } } } }
Let's say you need to log 100 error messages. That means that potential user is going to click "OK" 100 times:mad:. Cool, isn't it? And if this logger occasionally gets into some ASP.NET application... :((
Ouch.
-
I guess many of you have heard about log4j, log4net, log4cplus logging libraries. I'm going to show you the worst log appender I've ever seen. It shows message boxes!
class CustomLogAppender : FileAppender { protected override void Append(LoggingEvent loggingEvent) { base.Append(loggingEvent); if (loggingEvent.Level >= Level.Info) { if (Application.OpenForms != null && Application.OpenForms.Count > 0) { if (loggingEvent.Level == Level.Info) { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Exclamation); } else { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Error); } } } } }
Let's say you need to log 100 error messages. That means that potential user is going to click "OK" 100 times:mad:. Cool, isn't it? And if this logger occasionally gets into some ASP.NET application... :((
Perhaps this is for debugging, but from what you have put it could work quite well anyway. It shows that only logs with error level of info or above (presume warning) are show to the user - and correct me if I am wrong but I think you should let the user no when an error has occurred (at level info or higher) I presume there are levels such as 'Silent' or 'System' which will simply log the data in what ever storage it logs in
I may or may not be responsible for my own actions
modified on Wednesday, March 23, 2011 12:33 PM
-
Perhaps this is for debugging, but from what you have put it could work quite well anyway. It shows that only logs with error level of info or above (presume warning) are show to the user - and correct me if I am wrong but I think you should let the user no when an error has occurred (at level info or higher) I presume there are levels such as 'Silent' or 'System' which will simply log the data in what ever storage it logs in
I may or may not be responsible for my own actions
modified on Wednesday, March 23, 2011 12:33 PM
You know, any logger should never show any message boxes by definition. By the way, one of our testers ran into situation with these "debugging purposes". There was a bunch (near 10) message boxes one after another. And she was tired of clicking "OK".
-
I guess many of you have heard about log4j, log4net, log4cplus logging libraries. I'm going to show you the worst log appender I've ever seen. It shows message boxes!
class CustomLogAppender : FileAppender { protected override void Append(LoggingEvent loggingEvent) { base.Append(loggingEvent); if (loggingEvent.Level >= Level.Info) { if (Application.OpenForms != null && Application.OpenForms.Count > 0) { if (loggingEvent.Level == Level.Info) { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Exclamation); } else { ((MainForm)Application.OpenForms\[0\]).MessageBox(loggingEvent.RenderedMessage, "Application", MsgBoxButtons.OK, MsgBoxIcon.Error); } } } } }
Let's say you need to log 100 error messages. That means that potential user is going to click "OK" 100 times:mad:. Cool, isn't it? And if this logger occasionally gets into some ASP.NET application... :((
That's painful. Reminds me of when I first learned exception handling... I programmed a message box for most, if not all, exceptions... Don't worry. I've learned. :-D