Skip to content

Use Path.GetFullPath() to check for full path of the input path in FileLoggerConfigurationExtensions. #257

@AraHaan

Description

@AraHaan

.WriteTo.File() could use this for when the user only specifies path\filename.txt instead of the absolute path to where Path.GetFullPath() would resolve it automatically to the current working directory of the process itself.

Why is this needed? Well for me, I had problems with having serilog resolve this when serilog is in it's own shared framework (yes I wanted to make my own serilog shared framework that I can share with multiple projects of mine without issues). What happened was that the logs were not being written in the location I wanted because Path.GetFullPath() is not used for all of the overloads for .WriteTo.File(). Note: if the passed in path is already the absolute path, I think Path.GetFullPath() will simply return that path unchanged. But it is worth some testing to ensure that it does work like that.

It might be argued that I could just simply use Environment.CurrentDirectory in my code that calls .WriteTo.File however I do not directly call that and instead load the configuration from my appsettings.json file (unless the path option in the json file allows for string interpolation using .NET properties to fill in the CurrentDirectory when the setting is read).

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