'Logging errors by serilog-timings at loglevel "Error"
I show my idea on the serilog-timing example.
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.LiterateConsole()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
Log.Information("Hello, world!");
var count = 10000;
using (var op = Operation.Begin("Adding {Count} successive integers", count))
{
try
{
var sum = Enumerable.Range(0, count).Sum();
Log.Information("This event is tagged with an operation id");
var x= 0;
var y = 1/x;
op.Complete("Sum", sum);
}
catch(System.Exception ex)
{
op.Abandon(ex, LogEventLevel.Error);
}
Log.Information("Goodbye!");
}
Log.CloseAndFlush();
}
Unfortunately, the op.Abandon()
method currently doesn't have the second parameter which would set the log level. It creates always a Warning-level log item. I can make the modification in serilog-timing (adding a 2-parameter override of op.Abandon()
) but perhaps there is also a workaround for this issue, like in the case of our last question. So, my question is, can I achieve the desired result without this modification, or this time, I can't avoid making the necessary changes in the serilog-timing project?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|