|
[
Permlink
| « Hide
]
Nicko Cadell added a comment - 01/Mar/05 07:28 AM
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.
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. 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. 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 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||