-
-
Save optical/6e47c7e46fbba839ab22ba92c0d536ee to your computer and use it in GitHub Desktop.
InvalidCastException - Serilog.Exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using Serilog; | |
using Serilog.Debugging; | |
using Serilog.Exceptions; | |
using Serilog.Formatting.Json; | |
namespace ExceptionTest { | |
static class Program { | |
static void Main(string[] args) { | |
SelfLog.Enable(msg => Console.WriteLine($"Something bad happened!\n {msg}")); | |
var logger = new LoggerConfiguration() | |
.Enrich.WithExceptionDetails() | |
.WriteTo.Console() | |
.CreateLogger(); | |
try { | |
throw new MyException(); | |
} catch (Exception exception) { | |
logger.Error(exception, "Somethings bad"); | |
} | |
logger.Information("Done!"); | |
} | |
} | |
class MyException : Exception { | |
public override IDictionary Data => new Dictionary<string, object> { | |
["SomeValue"] = 1 | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment