You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Daniel Lidström (Jira)" <ji...@apache.org> on 2020/04/05 11:53:00 UTC

[jira] [Commented] (LOG4NET-615) Expose members in SystemStringFormat

    [ https://issues.apache.org/jira/browse/LOG4NET-615?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17075801#comment-17075801 ] 

Daniel Lidström commented on LOG4NET-615:
-----------------------------------------

😢 too bad!

> Expose members in SystemStringFormat
> ------------------------------------
>
>                 Key: LOG4NET-615
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-615
>             Project: Log4net
>          Issue Type: Wish
>          Components: Layouts
>    Affects Versions: 2.0.8
>            Reporter: Daniel Lidström
>            Priority: Trivial
>
> 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|https://gist.github.com/dlidstrom/d7770f8e4b774a6d9a897de1e83e57bb].
> 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



--
This message was sent by Atlassian Jira
(v8.3.4#803005)