I wrote the following line to create my logger in a C#/WPF application, but the Debug messages do not show up in the logs. What am I missing? I am using serilog.sinks.file version 4.0.0. The release build produces information level events, but the debug build does not produce debug messages. I have confirmed that the DEBUG symbol is defined, and I've debugged to confirm that the level is in fact set to debug.
LogEventLevel level = LogEventLevel.Information;
#if DEBUG
level = LogEventLevel.Debug;
#endif
UsageLogger = new LoggerConfiguration()
.Enrich.With(new ThreadIdEnricher())
.WriteTo.File("UsageLogging.txt", restrictedToMinimumLevel: level, outputTemplate: LogTemplate, rollingInterval: RollingInterval.Day)
.Enrich.With(new ThreadIdEnricher())
.WriteTo.Console(restrictedToMinimumLevel: level, outputTemplate: LogTemplate)
.Enrich.With(new ThreadIdEnricher())
.CreateLogger();
}
debug . This combination of a configurable logging level and logging statements within your program allow you full control over how your application will log its activity.
To view a debug log, from Setup, enter Debug Logs in the Quick Find box, then select Debug Logs. Then click View next to the debug log that you want to examine. Click Download to download the log as an XML file. Debug logs have the following limits.
Debug logs are system-generated logs that are sent to your Dashboard along with every new conversation. They only appear if your developers have configured them in the SDK for a given game/app version. When configured, they appear under the metadata tab in the Issue details pane.
I think it would need to be this...
LogEventLevel level = LogEventLevel.Information;
#if DEBUG
level = LogEventLevel.Debug;
#endif
UsageLogger = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
#endif
.Enrich.With(new ThreadIdEnricher())
.WriteTo.File("UsageLogging.txt", restrictedToMinimumLevel: level, outputTemplate: LogTemplate, rollingInterval: RollingInterval.Day)
.Enrich.With(new ThreadIdEnricher())
.WriteTo.Console(restrictedToMinimumLevel: level, outputTemplate: LogTemplate)
.Enrich.With(new ThreadIdEnricher())
.CreateLogger();
Mine is an asp.net core 2.0 project and reading the config from appsetting.Development.json file
In the Startup.cs file, first you need to create the logger as follows.
var seriLogger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Here its important to note that the minimum level is set to Verbose. Note
.MinimumLevel.Verbose()
Next the appsettings.Developement.json would look like the following.
{
"ConnectionStrings": {
"HPlusSportsConnection": "Data Source=DESKTOP-Feast\\sqlexpress;Initial Catalog=H_Plus_Sports;Persist Security Info=True;User ID=fakeUserId;Password=fakePassword"
},
"Serilog": {
"WriteTo": [
{
"Name": "Seq",
"Args": {
"restrictedToMinimumLevel": "Debug",
"serverUrl": "http://localhost:5341"
}
},
{
"Name": "File",
"Args": {
"restrictedToMinimumLevel": "Verbose",
"path": "log.txt",
"outputTemplate": "Will be logged {Timestamp:yyyy-MMM-dd HH:mm:ss}|{TenantName}|{RequestId}|{SourceContext}|{Level:u3}|{Message:lj}{NewLine}{Exception}",
"rollingInterval": "Day"
}
}
]},}
So I have multiple sinks and each has its own level. The sink Seq has Debug, so debug and above will be logged to seq sink. And to the text file, the level is Verbose, to effectively everything will be logged.
Again to emphasize,
.MinimumLevel.Verbose()
is important here. If you omit or comment out that, then file as well as seq will have only logs from information and above, even though you configured them to verbose or debug. Thats because minimum level is by default "Information".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With