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

PatternString "properties" in config file

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Other
    • None

    Description

      The PatternString has many built-in conversion patterns but none of them can use properties defined in the configuration file. The PatternString should also help to prevent copy paste errors and use the DRY pattern also in the config file. If you have many log files and they log in the same path, you would like to define the log path only once. If you want to change the log path, you would like to change it only in one place and not in many places.
      Perhaps the most interesting converter is the "property" converter but you can't define global properties in the configuration file. The log4net global properties are nice but they are embedded in code and compiled with the application.

      My suggestions are: Define log4net global properties in the configuration file:
      <log4net>
      <globalproperties>
      <add key="logpath" value="c:\logs\myapplication\" />
      </globalproperties>
      <appender>
      <file value="%properties

      {logpath}log.txt" />
      </appender>
      </log4net>

      Or add an appsettings converter to the PatternString:
      <appSettings>
      <add key="logpath" value="c:\logs\myapplication\" />
      </appSettings>
      <log4net>
      <appender>
      <file value="%appsettings{logpath}

      log.txt" />
      </appender>
      </log4net>

      There are also other cases where configuring part of the log path globally is useful, most of the time you have different environments: test, staging, production, demo, etc. and some times you have different type of the same environment: test-configuration1, test-configuration2, etc. So the ability to build the log file path from properties defined in the config file is an added value in those cases.
      In those cases I have to set the properties only once in one place and I haven't to change the log file path of every logger, this would prevent errors like logger logging in the wrong place and it would simplify the deploy and configuration process.

      Attachments

        Activity

          People

            Unassigned Unassigned
            casualuser Casul User
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: