Skip to content

How to create the log file by process name? #411

@xuliujian

Description

@xuliujian

I create a common trace library for other solutions. But I can not find a way to configure the path dynamicly.
I tried to create a enrich to add a property named InstanceName, but it does not work.

{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{TraceCategory} - {Timestamp:o} [{Level:u3}] {Message}{NewLine}"
}
},
{
"Name": "File",
"Args": {
"path": "./logs/{InstanceName}.log",
"outputTemplate": "{TraceCategory} - {Timestamp:o} [{Level:u3}] {Message}{NewLine}",
"rollingInterval": "Day",
"retainedFileCountLimit": 7
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithTraceCategory", "WithInstanceName" ],
"Destructure": [
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 4 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 100 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 10 }
}
]
}
}

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