Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-615

Expose members in SystemStringFormat

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 2.0.8
    • None
    • Layouts
    • None

    Description

      Hello

       

      I'm trying to create a structured logging format and have a conversion pattern with a custom converter like this:

       

            <layout type="log4net.Layout.PatternLayout">

              <conversionPattern value="%date [%2thread] %-5level [%property

      {NDC}

      ] %username - type=%message_checksum %message%newline" />

              <converter>

                <name value="message_checksum" />

                <type value="TestBed.MessageChecksumConverter" />

              </converter>

            </layout>

       

      The interesting part of course is the message_checksum. For example, I am logging like this:

       

                      Log.Debug("some debugging message");

                      Log.Info(new { Id = 1, Name = "the name" });

                      Log.InfoFormat("Logging msg {0}", 1);

                      Log.InfoFormat("Logging msg {0}", 2);

                      Log.InfoFormat("Logging msg {0}", 3);

       

      I would like the output to be something like this

       

      2018-10-26 11:06:44,564 [ 1] DEBUG [(null)] XXX - type=f6d5 some debugging message

      2018-10-26 11:06:44,638 [ 1] INFO  [(null)] XXX - type=e0e3 { Id = 1, Name = the name }

      2018-10-26 11:06:44,648 [ 1] INFO  [(null)] XXX - type=32a6 Logging msg 1

      2018-10-26 11:06:44,656 [ 1] INFO  [(null)] XXX - type=32a6 Logging msg 2

      2018-10-26 11:06:44,663 [ 1] INFO  [(null)] XXX - type=32a6 Logging msg 3

       

      As you can see, I am getting the type=32a6 for the last 3 logging messages. This allows me to search for all of those, regardless of the parameters given.

      For example, I can now search and group the number of errors by their unique type and know which error is most common in our system.

       

      To implement this, I created the MessageChecksumConverter.

      I am reading SystemStringFormat.m_format by using reflection. That gives me the string template used when logging and it is the one I think is appropriate when outputting the type of the log message.

       

      Now to my feature request: please expose the internals of SystemStringFormat so that I can do this in a safe way.

      What do you think?

       

      Regards,

      Daniel Lidström

      Attachments

        Activity

          People

            Unassigned Unassigned
            dlidstrom Daniel Lidström
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: