Skip to content

Instantly share code, notes, and snippets.

@niemyjski

niemyjski/exceptionless.cs

Last active Dec 15, 2020
Embed
What would you like to do?
Exceptionless Ignore Third Party Exceptions
// Create our own client instance so we aren't conflicting if anyone else is using exceptionless in an addon.
private readonly ExceptionlessClient _client = new ExceptionlessClient();
_client.Configuration.AddPlugin<IgnoreLicensingAndNonGeneratorExceptionsPlugin>();
[Priority(30)]
private class IgnoreLicensingAndNonGeneratorExceptionsPlugin : IEventPlugin {
private static readonly List<string> _handledNamespaces = new List<string> {
"MyNamespace",
"MyThirdPartyDependencyNamespace"
};
public void Run(EventPluginContext ctx) {
if (!ctx.ContextData.IsUnhandledError || !ctx.Event.IsError() || !ctx.ContextData.HasException())
return;
var exception = ctx.ContextData.GetException();
if (exception == null)
return;
var error = ctx.Event.GetError();
if (error == null)
return;
//Ignore any unhandled exceptions that were not thrown by our code.
if (!error.StackTrace.Select(s => s.DeclaringNamespace).Distinct().Any(ns => _handledNamespaces.Any(ns.Contains)))
ctx.Cancel = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment