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

Support per event patterns in FileAppender File name

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.9
    • Fix Version/s: 1.2.10
    • Component/s: Appenders
    • Labels:
      None
    • Environment:
      From sourceforge: 812999

      Description

      If I could specify file name patter for
      (Rolling)FileAppender that would be filled by the
      appender prior to openning the file, I could let many
      individuals run the same applikation (on terminal
      server) and still log to file (not RemotingAppender or
      ADONetAppernder)

      I guess, pattern like "rootLog%U.log" would do, if
      appender replaced %U with
      Thread.CurrentThread.CurrentPrincipal.Identity.Name ...
      Or %T with thread id and so on...

      Anonymous

        Activity

        Hide
        nicko Nicko Cadell added a comment -

        The FileAppender holds the file open. Closing and opening the file for each request may have performance issues. We could look at holding a number of files open at one time. log4j has done something similar using an appender that can create new appenders from a template at runtime.

        Show
        nicko Nicko Cadell added a comment - The FileAppender holds the file open. Closing and opening the file for each request may have performance issues. We could look at holding a number of files open at one time. log4j has done something similar using an appender that can create new appenders from a template at runtime.
        Hide
        roseen Göran Roseen added a comment -

        If the pattern only expands "application-static" info, such as username, or the thread ID of the initial thread, the pattern could be expanded at the time the appender is initialized.

        That way, we have no problem with opening/closing log files, and still can satisfy the need to have user-specific or instance-specific log files.

        Show
        roseen Göran Roseen added a comment - If the pattern only expands "application-static" info, such as username, or the thread ID of the initial thread, the pattern could be expanded at the time the appender is initialized. That way, we have no problem with opening/closing log files, and still can satisfy the need to have user-specific or instance-specific log files.
        Hide
        nicko Nicko Cadell added a comment -

        This issue is really about a single application instance logging separate files for each user. For example, an authenticated web service knows the identity of the calling user, actions performed by the service on behalf of the use could be logged into separate files for each user.

        There are two ways to achieve this.

        Firstly to evaluate the file name on a per event basis and open the appropriate file per event. This can be optimised by only closing and reopening the file if the name changes from one event to the next. This still could cause quite a large overhead. This is technically possible using the FileAppender's pluggable locking model objects, however this would 'confuse' the appender with respect to headers and footers.

        Secondly to create a FileAppender for each output file, these appenders are held open behind a router appender that selects the appropriate appender to write to. If no appropriate appender currently exists then one is created. This requires a second level of templating and the ability to parse a fragment of XML config. This has been implemented in log4j 1.3.

        Show
        nicko Nicko Cadell added a comment - This issue is really about a single application instance logging separate files for each user. For example, an authenticated web service knows the identity of the calling user, actions performed by the service on behalf of the use could be logged into separate files for each user. There are two ways to achieve this. Firstly to evaluate the file name on a per event basis and open the appropriate file per event. This can be optimised by only closing and reopening the file if the name changes from one event to the next. This still could cause quite a large overhead. This is technically possible using the FileAppender's pluggable locking model objects, however this would 'confuse' the appender with respect to headers and footers. Secondly to create a FileAppender for each output file, these appenders are held open behind a router appender that selects the appropriate appender to write to. If no appropriate appender currently exists then one is created. This requires a second level of templating and the ability to parse a fragment of XML config. This has been implemented in log4j 1.3.
        Hide
        nicko Nicko Cadell added a comment -

        The log4net.Util.PatternString type allows patterns to be specified in the FileAppender File property at configuration time. This can be used to allow multiple copies of the same application to log to separate log files.

        There is also an example appender in the SampleAppendersApp that allows event specific patterns to be used in the file name. The appender constructs the file name for each event using a PatternLayout, the file is opened and closed for each event.

        For more details see
        examples\net\1.0\Appenders\SampleAppendersApp\cs\src\Appender\PatternFileAppender.cs

        Show
        nicko Nicko Cadell added a comment - The log4net.Util.PatternString type allows patterns to be specified in the FileAppender File property at configuration time. This can be used to allow multiple copies of the same application to log to separate log files. There is also an example appender in the SampleAppendersApp that allows event specific patterns to be used in the file name. The appender constructs the file name for each event using a PatternLayout, the file is opened and closed for each event. For more details see examples\net\1.0\Appenders\SampleAppendersApp\cs\src\Appender\PatternFileAppender.cs
        Hide
        zsu zsu added a comment -

        Check out the RollingPatternFileAppender at http://mysite.verizon.net/vze14bhji/RollingPatternFileAppender.htm
        It can create log file with dynamic name and has all the rolling features like RollingFileAppender.

        Show
        zsu zsu added a comment - Check out the RollingPatternFileAppender at http://mysite.verizon.net/vze14bhji/RollingPatternFileAppender.htm It can create log file with dynamic name and has all the rolling features like RollingFileAppender.

          People

          • Assignee:
            nicko Nicko Cadell
            Reporter:
            nicko Nicko Cadell
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development