Custom log4net property PatternLayoutConverter (with index)

后端 未结 1 496
滥情空心
滥情空心 2020-12-04 02:16

Is it possible to create a log4net custom PatternLayoutConverter that allows an \"index\" value to be configured? I know about the \"property\" conversion string that allow

相关标签:
1条回答
  • 2020-12-04 02:37

    I did not try it but this should work. In log4net you can pass an option string to a pattern converter like this:

    %converterName{converterOptions}
    

    The date pattern converter for instance can be used like this:

    %date{HH:mm:ss,fff}
    

    This means you can write your pattern converter the way you suggested. A simple example for such a converter can be found here.

    In the Convert method you can access the the property string with the property 'Option' (defined in the PatternConverter class) and use the thread context to get the desired entry from the dictionary. You can also implement the IOptionHandler interface if your options consist of more then just the dictionary key: This way you can parse the options upon activation of the log4net configuration.

    0 讨论(0)
提交回复
热议问题