Skip to content

Instantly share code, notes, and snippets.

@optical
Last active March 21, 2017 01:12
Show Gist options
  • Save optical/6e47c7e46fbba839ab22ba92c0d536ee to your computer and use it in GitHub Desktop.
Save optical/6e47c7e46fbba839ab22ba92c0d536ee to your computer and use it in GitHub Desktop.
InvalidCastException - Serilog.Exceptions
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