Skip to content

Get rolling file name index #53

@Crypt32

Description

@Crypt32

This is related to #5, but not exactly.
Here is my NReco.Logging registration with .NET DI:

services.AddLogging(loggingBuilder => {
        loggingBuilder.AddFile("Logs\\app_{0:yyyy}-{0:MM}-{0:dd}.log", fileLoggerOpts => {
        fileLoggerOpts.FormatLogFileName = getLogFileName;
        fileLoggerOpts.FileSizeLimitBytes = 1 * 1024 * 1024; // 1MB
        fileLoggerOpts.MaxRollingFiles = 10;
        fileLoggerOpts.UseUtcTimestamp = true;
    });
})

<...>
// callback for FormatLogFileName 
static String getLogFileName(String fName) {
    // cache current file name in static property:
    LogFilePath = String.Format(fName, DateTime.UtcNow);

    return LogFilePath;
}

Everything works ok with one exception: I loose current file name tracking when log file is rolled. By looking in Logs directory, I see that file names are appended with rolling index:
image

And I have no idea how to access this index so I reference to actual current file in LogFilePath property. Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions