serilog-settings-configuration icon indicating copy to clipboard operation
serilog-settings-configuration copied to clipboard

How to create the log file by process name?

Open xuliujian opened this issue 1 year ago • 3 comments

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 } } ] } }

xuliujian avatar Jan 31 '24 08:01 xuliujian