Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Wonderful logger

Wonderful logger

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpasp-nethelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vladimir Svyatski
    wrote on last edited by
    #1

    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... :((

    M M D 3 Replies Last reply
    0
    • V Vladimir Svyatski

      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... :((

      M Offline
      M Offline
      Marc A Brown
      wrote on last edited by
      #2

      Ouch.

      1 Reply Last reply
      0
      • V Vladimir Svyatski

        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... :((

        M Offline
        M Offline
        musefan
        wrote on last edited by
        #3

        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

        V 1 Reply Last reply
        0
        • M musefan

          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

          V Offline
          V Offline
          Vladimir Svyatski
          wrote on last edited by
          #4

          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".

          1 Reply Last reply
          0
          • V Vladimir Svyatski

            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... :((

            D Offline
            D Offline
            drummerboy0511
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups