Skip to content

FileLoggerProcessor should update FileNumber suffix when FileName changes #34809

@wtgodbe

Description

@wtgodbe

private string _fileName = "w3clog-";

When FileName changes, we should reset FileNumber back to 0 instead of continuing where we left off.

_options.OnChange(options =>
{
lock (_pathLock)
{
// Clear the cached settings.
loggerOptions = options;
if (!string.IsNullOrEmpty(loggerOptions.LogDirectory))
{
_path = loggerOptions.LogDirectory;
}
_fileName = loggerOptions.FileName;
_maxFileSize = loggerOptions.FileSizeLimit;
_maxRetainedFiles = loggerOptions.RetainedFileCountLimit;
_flushInterval = loggerOptions.FlushInterval;
}
});

But it might be somewhat tricky - e.g. OnChange fires in the middle of execution of WriteMessagesAsync, causing the FileNumber to go back to zero. If this happens while we're scanning through some previous files to find out if they exist, it could cause us to suffix the first file with the new name with something nonzero. I'll file a follow-up issue for this one, for now I think it's fine if the numbering for the new file names pick up where the old ones left off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-http-logging

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions