Skip to content

Dynamic Log Filenames #40

@ltoshea

Description

@ltoshea

I currently am writing to a statically named log file as defined in my serilog config:
<add key="serilog:write-to:File.path" value="%LOCALAPPDATA%\App_Data\Logs\StaticallyNamedLog.log" />
I'd like to be able to change the logfile name at runtime i.e.

<add key="serilog:write-to:File.path" value="%LOCALAPPDATA%\App_Data\Logs\{appname}-Log.log" />

In log4net for example I'd set a log4net global property value for "appname" in code before the settings were read in. This would then get substituted into this path.

    log4net.globalContext.properties["appname"] = "App1"
    log4net.config.xmlConfigurator.configure("log4net.config")

Then in the logfile I'd reference it like so

%property{appname}

This would then get substituted into this path.

I've really tried to find a solution to this but to no avail - can someone offer any advice as to how I might achieve this?

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