Log4net
  1. Log4net
  2. LOG4NET-316

Provide a Layout Pattern that is re-evaluated on each use

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.11
    • Fix Version/s: 1.2.12
    • Component/s: Other
    • Labels:

      Description

      The DynamicPatternLayout is a layout pattern that is re-evaluated on each use. It is appropriate to use instead of LayoutPattern to provide dynamic strings in headers and footers for appenders. Datetime is an example. Using the standard layout pattern results in the same datetime in each header and footer, while using DynamicPatternLayout results in timestamp of the header/footer creation.

      Example
      <layout type="log4net.Layout.DynamicPatternLayout">
      <param name="Header" value="%newline**** Trace Opened Local: %date

      {yyyy-MM-dd HH:mm:ss.fff}

      UTC: %utcdate

      {yyyy-MM-dd HH:mm:ss.fff}

      ****%newline"/>
      <param name="Footer" value="**** Trace Closed %date

      {yyyy-MM-dd HH:mm:ss.fff}

      ****%newline"/>
      </layout>

        Issue Links

          Activity

          Hide
          Stefan Bodewig added a comment -

          code looks good to me but I wonder whether it wouldn't be easier to add a property "dynamic" to the existing PatternLayout rather than creating a subclass.

          Show
          Stefan Bodewig added a comment - code looks good to me but I wonder whether it wouldn't be easier to add a property "dynamic" to the existing PatternLayout rather than creating a subclass.
          Hide
          Roy Chastain added a comment -

          Honestly, I do not know. I asked about this feature some time back and Ron G. suggested this approach.

          Show
          Roy Chastain added a comment - Honestly, I do not know. I asked about this feature some time back and Ron G. suggested this approach.
          Hide
          Stefan Bodewig added a comment -

          What would be your personal choice if you had free reign?

          Show
          Stefan Bodewig added a comment - What would be your personal choice if you had free reign?
          Hide
          Roy Chastain added a comment -

          Given my somewhat limited knowledge of the log4Net code base and internal design, the sub-classing seemed like a simple and clean implementation. It allows for new functionality without adding logic the the PattenLayout base class and therefore minimizes the chance of breaking the existing implementation.

          So, yes other than the fact that I have created a very small class and added to class proliferation, I am happy with the sub-classing.

          Show
          Roy Chastain added a comment - Given my somewhat limited knowledge of the log4Net code base and internal design, the sub-classing seemed like a simple and clean implementation. It allows for new functionality without adding logic the the PattenLayout base class and therefore minimizes the chance of breaking the existing implementation. So, yes other than the fact that I have created a very small class and added to class proliferation, I am happy with the sub-classing.
          Hide
          Stefan Bodewig added a comment -

          Code is in as svn revision 1210987

          I've added a tiny test that shows the subclass didn't break anything we actually test for PatternLayout. But then again we don't test header and footer handling in PatternLayout at all.

          So far I've not marked this issue as resolved in order to remind us we need to document it somewhere somehow.

          Show
          Stefan Bodewig added a comment - Code is in as svn revision 1210987 I've added a tiny test that shows the subclass didn't break anything we actually test for PatternLayout. But then again we don't test header and footer handling in PatternLayout at all. So far I've not marked this issue as resolved in order to remind us we need to document it somewhere somehow.
          Hide
          Roy Chastain added a comment -

          The XML comments in the code should explain how (and when) to use the DynamicPatternLayout so a rebuild of the SDK reference should provide the needed documentation. Perhaps we could simply add it to one of the logging examples show on the log4Net site.
          Is there an FAQ on how to modify the webpages that are displayed on the site?

          Show
          Roy Chastain added a comment - The XML comments in the code should explain how (and when) to use the DynamicPatternLayout so a rebuild of the SDK reference should provide the needed documentation. Perhaps we could simply add it to one of the logging examples show on the log4Net site. Is there an FAQ on how to modify the webpages that are displayed on the site?
          Hide
          Stefan Bodewig added a comment -

          I agree with the SDK docs.

          The site itself is built using Apache Maven (I use 2.2.1 and a command line of mvn site:site). It is generated from the files in src/site, most of which use the XDOCs format described in http://maven.apache.org/doxia/references/xdoc-format.html

          Show
          Stefan Bodewig added a comment - I agree with the SDK docs. The site itself is built using Apache Maven (I use 2.2.1 and a command line of mvn site:site). It is generated from the files in src/site, most of which use the XDOCs format described in http://maven.apache.org/doxia/references/xdoc-format.html
          Hide
          Dominik Psenner added a comment -

          Added a config example with revision: 1489735

          Show
          Dominik Psenner added a comment - Added a config example with revision: 1489735

            People

            • Assignee:
              Dominik Psenner
              Reporter:
              Roy Chastain
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development