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

Is it possible to create a log file based on the Application running as I need log based on that and with the appsettings.json

Open SAILAKSHMIBHATTARAM opened this issue 4 years ago • 2 comments

Hi I'm using serilog and trying writeto.File(), reading configuration from appsettings.json file.. But the problem here is I need two log files based on the application name, since I will be using the serilog project as a utility based on the Assembly from which the application is running I should create respective files. I tried adding filters in json file for writeto tag there is no luck. { "Serilog": { "Using": [ "Serilog.Sinks.File" ], "FilterSwitches": { "$filterSwitch": "Application = 'Adaptor.Service'"}, "MinimumLevel": { "Default": "Debug" }, "WriteTo": [ { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "inclusionPredicate": { "logEvent": { "Properties": { "Application": "Adaptor.Service" } } } } } ], "Enrich": [ "FromLogContext", "WithMachineName", { "Name": "When", "Args": { "expression": "Application = Adaptor.Service'" }, "configureEnricher": [ "WithMachineName", "FromLogContext", "WithThreadId" ] } ], "WriteTo": [ { "Name": "File", "Args": { "path": "%TEMP%/Logs/AdaptorConfig2.txt", "outputTemplate": "[{Timestamp:HH:mm:ss}] {SourceContext} [{Level}] {Message}{NewLine}{Exception}" } } ] } } }, { "Name": "Logger", "Args": { "configureLogger": { "Filter": [ { "Name": "ByIncludingOnly", "Args": { "inclusionPredicate": { "logEvent": { "Properties": { "Application": "TestApp.Service" } } } } } ], "Enrich": [ "FromLogContext", "WithMachineName", { "Name": "When", "Args": { "expression": "Application = 'TestApp.Service'" }, "configureEnricher": [ "WithMachineName", "FromLogContext", "WithThreadId" ] } ], "WriteTo": [ { "Name": "File", "Args": { "path": "%TEMP%/Logs/TestAppConfig2.txt", "outputTemplate": "[{Timestamp:HH:mm:ss}] {SourceContext} [{Level}] {Message}{NewLine}{Exception}" } } ] } } } ] } }

SAILAKSHMIBHATTARAM avatar Feb 26 '21 11:02 SAILAKSHMIBHATTARAM

You can place three backticks (`) before and after your code to create a code block.

just
like
this

dsbert avatar Mar 16 '21 16:03 dsbert

Thanks for getting in touch @SAILAKSHMIBHATTARAM - Stack Overflow is a better option for usage questions, as there are more people over there able to answer.

nblumhardt avatar Mar 16 '21 21:03 nblumhardt