serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
453 stars 129 forks source link

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 #251

Open SAILAKSHMIBHATTARAM opened 3 years ago

SAILAKSHMIBHATTARAM commented 3 years ago

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

dsbert commented 3 years ago

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

just
like
this
nblumhardt commented 3 years ago

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.