Skip to content

v3.1.0 - Exception with RollingFileAppender when files are already present #244

@eimhof

Description

@eimhof

I just updated from v3.0.4 to 3.1.0 and suddenly logging fails with an ArgumentException ("The path is not of a legal form.")

Stack:

at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.InternalGetDirectoryName(String path)
   at log4net.Appender.RollingFileAppender.InitializeFromOneFile(String baseFile, String curFileName)
   at log4net.Appender.RollingFileAppender.InitializeRollBackups(String baseFile, IList`1 arrayFiles)
   at log4net.Appender.RollingFileAppender.DetermineCurSizeRollBackups()
   at log4net.Appender.RollingFileAppender.ExistingInit()
   at log4net.Appender.RollingFileAppender.ActivateOptions()
   at log4net.Program.Main(String[] args) in D:\Temp\Egbert\log4net\log4net\Program.cs:line 29

It turns out that when there's already a file present in the target directory, above mentioned error is thrown.

Below a repro - first time you run it, it will work because no file is present. The second time it fails:

static void Main(string[] args)
{
    PatternLayout patternLayout = new PatternLayout
    {
        ConversionPattern = @"%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"
    };
    patternLayout.ActivateOptions();

    RollingFileAppender rollingFileAppender = new RollingFileAppender
    {
        AppendToFile = true,
        File = @"C:\TempLog\",
        Layout = patternLayout,
        DatePattern = "yyyy-MM-dd'.log'",
        MaxSizeRollBackups = 10,
        MaximumFileSize = "5MB",
        RollingStyle = RollingFileAppender.RollingMode.Composite,
        StaticLogFileName = false,
    };
    rollingFileAppender.ActivateOptions();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions