I have a console application with Target framework 8.0.
I would like to log ThreadId to console output of my serilog log. ThreadId is getting logged to json file but in console it does not log ThreadId.Below is my configuration,
{"Serilog": {"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async" ],"MinimumLevel": "Debug","WriteTo": [ {"Name": "Async","Args": {"configure": [ {"Name": "Console","Args": {"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console","formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog","outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}" } }, {"Name": "File","Args": {"path": "logs/schedular_log_.json","rollingInterval": "Day","shared": true,"rollOnFileSizeLimit": true,"retainedFileCountLimit": 7,"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog" } } ] } } ],"Enrich": [ "WithThreadId", "FromLogContext", "WithExceptionDetails" ],"Properties": {"Application": "Schedular" } }}
Below is the result in Console log,
[13:29:12 INF] {"Id": "bb497c8e-9e92-4981-9c98-d3e94ed1b009", "Name": "Mat0", "Created": "2024-04-01T13:29:12.0955808+05:30", "Description": "MatDescription0", "$type": "Material"} <s:>[13:29:12 INF] {"Id": "98ccbe47-e62a-406a-9eb2-01c7314131e9", "Name": "Mat1", "Created": "2024-04-01T13:29:12.2064649+05:30", "Description": "MatDescription1", "$type": "Material"} <s:>
But in my json file log, I get the below result,
{"Timestamp":"2024-04-01T13:29:12.2068098+05:30","Level":"Information","MessageTemplate":"{@Material}","Properties":{"Material":{"Id":"aac4815f-5ea1-4527-9558-6f0d868cd41c","Name":"Mat7","Created":"2024-04-01T13:29:12.2068090+05:30","Description":"MatDescription7","_typeTag":"Material"},"ThreadId":1,"Application":"Schedular"}}{"Timestamp":"2024-04-01T13:29:12.2068150+05:30","Level":"Information","MessageTemplate":"{@Material}","Properties":{"Material":{"Id":"25944fb5-a50a-4b74-b561-79c775fadd2b","Name":"Mat8","Created":"2024-04-01T13:29:12.2068147+05:30","Description":"MatDescription8","_typeTag":"Material"},"ThreadId":1,"Application":"Schedular"}}{"Timestamp":"2024-04-01T13:29:12.2068182+05:30","Level":"Information","MessageTemplate":"{@Material}","Properties":{"Material":{"Id":"6d59c4a6-ba2d-46c8-b3ce-f7ccd7dfff9c","Name":"Mat9","Created":"2024-04-01T13:29:12.2068181+05:30","Description":"MatDescription9","_typeTag":"Material"},"ThreadId":1,"Application":"Schedular"}}
Notice ThreadId in file log and not in console log. Is there a way to have the console log ThreadId.I would prefer to configure through json only.