Skip to content

Instantly share code, notes, and snippets.

@ejsmith
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejsmith/53cd2341dcab8cf79eee to your computer and use it in GitHub Desktop.
Save ejsmith/53cd2341dcab8cf79eee to your computer and use it in GitHub Desktop.
Examples of using the Exceptionless 2.0 client
var client = new ExceptionlessClient(config => {
// Set your API key.
config.ApiKey = "API_KEY_HERE";
// Send events to your own free Exceptionless server install.
config.ServerUrl = "https://exceptionless.myorg.com";
// Read config settings from attributes.
config.ReadFromAttributes();
// Read config settings from a config section in your app/web.config.
config.ReadFromConfigSection();
// Store all client data including the offline queue in the store folder, by default isolated storage is used.
config.UseFolderStorage("store");
// Exclude any form fields, cookies, query string parameters, and custom data properties containing "CreditCard".
config.AddDataExclusions("CreditCard");
// Add the "SomeTag" to all events.
config.DefaultTags.Add("SomeTag");
// Add the "MyObject" custom data object to every event.
config.DefaultData.Add("MyObject", new { MyProperty = "Value1" });
// Add a custom event enrichment that will add a tag called "MyTag" to every event.
config.AddEnrichment(ev => ev.Tags.Add("MyTag"));
// Register a custom log implementation that uses NLog.
config.Resolver.Register<IExceptionlessLog>(new NLogExceptionlessLog());
});
// The Startup method is specific for each platform and wires up to all relevant unhandled
// exception events so that they will be automatically sent to the server.
client.Startup();
// Manually catch and report an error with a custom tag on it.
try {
throw new ApplicationException("Boom!");
} catch (Exception ex) {
ex.ToExceptionless().AddTags("MyTag").Submit();
}
// Let users add their email address and a description of the error.
client.UpdateUserEmailAndDescription(client.GetLastReferenceId(), "me@me.com", "It broke!");
// Create and submit a log message and add an extra "Order" object to the event.
client.CreateLog("Order", "New order created.")
.AddObject(new { Total = 14.95 }, name: "Order")
.Submit();
// Submit a feature usage event that will let you see how much certain features of your app are being used.
client.SubmitFeatureUsage("FeatureA");
// Submit a page not found event so you can keep track of your broken links and fix them.
client.SubmitNotFound("/badpage");
// Listen to all events being sent and cancel any errors that are "IgnoredType".
client.SubmittingEvent += (sender, args) =>
args.Cancel = args.Event.IsError() && args.Event.GetError().Type.Contains("IgnoredType");
// Settings data is synced in real-time with the project settings in your Exceptionless project on the server.
client.Configuration.Settings.Changed += (sender, args) =>
Trace.WriteLine(String.Format("Action: {0} Key: {1} Value: {2}", args.Action, args.Item.Key, args.Item.Value));
// You can use those settings to control behaviour in your app.
if (client.Configuration.Settings.GetBoolean("IncludeMyCustomData", false))
Trace.WriteLine("Should include my custom data");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment