Getting Started with Exceptionless: Real‑time Error Logging for ASP.NET Core
This article introduces the open‑source Exceptionless framework, explains how to set up an account, integrate it into an ASP.NET Core project, configure logging and custom events with code examples, and shows how to view and manage collected error data.
Exceptionless is an open‑source, real‑time logging framework that can be used with ASP.NET, ASP.NET Core, Web API, MVC, WPF, Console and other .NET applications, as well as via REST APIs from JavaScript or Node.js.
To begin, register an account on the Exceptionless website (or deploy the server locally), then create a new project and select the appropriate project type, such as ASP.NET Core.
Install the NuGet package Exceptionless.AspNetCore and modify Startup.cs by adding the following code to the Configure method:
using Exceptionless;
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Replace the highlighted part with your project key
app.UseExceptionless("xxxxxxxxxxxxxxxxxxxxxxxxxx");
app.UseStaticFiles();
app.UseMvc();
}After these steps, Exceptionless will automatically capture unhandled exceptions in the project.
To view logged errors, run the application, trigger an exception (e.g., in HomeController.cs ), and refresh the Exceptionless dashboard, where you can see details such as exception type, timestamp, stack trace, IP address, browser, and more.
Exceptionless also supports sending various event types (Log, Feature Usage, 404, Custom Event). Example code for sending events:
using Exceptionless;
// Log
ExceptionlessClient.Default.SubmitLog("Logging made easy");
ExceptionlessClient.Default.SubmitLog(typeof(Program).FullName, "This is so easy", "Info");
ExceptionlessClient.Default.CreateLog(typeof(Program).FullName, "This is so easy", "Info").AddTags("Exceptionless").Submit();
// Feature usage
ExceptionlessClient.Default.SubmitFeatureUsage("MyFeature");
ExceptionlessClient.Default.CreateFeatureUsage("MyFeature").AddTags("Exceptionless").Submit();
// 404 event
ExceptionlessClient.Default.SubmitNotFound("/somepage");
ExceptionlessClient.Default.CreateNotFound("/somepage").AddTags("Exceptionless").Submit();
// Custom event
ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Low Fuel", Type = "racecar", Source = "Fuel System" });For manually submitted handled exceptions, wrap the caught exception with ex.ToExceptionless().Submit(); .
You can enrich events with additional context such as reference IDs, custom objects, tags, critical flags, geographic coordinates, and user information before calling .Submit(); .
To apply uniform processing to all events, subscribe to ExceptionlessClient.Default.SubmittingEvent and implement custom filtering or augmentation logic, for example ignoring 404s or specific error codes.
ExceptionlessClient.Default.SubmittingEvent += OnSubmittingEvent;
private void OnSubmittingEvent(object sender, EventSubmittingEventArgs e)
{
if (!e.IsUnhandledError) return;
if (e.Event.IsNotFound()) { e.Cancel = true; return; }
var error = e.Event.GetError();
if (error == null) return;
if (error.Code == "401" || error.Type == "System.Web.HttpRequestValidationException") { e.Cancel = true; return; }
var handledNamespaces = new List
{ "Exceptionless" };
if (!error.StackTrace.Select(s => s.DeclaringNamespace).Distinct().Any(ns => handledNamespaces.Any(ns.Contains))) { e.Cancel = true; return; }
e.Event.AddObject(order, "Order", excludedPropertyNames: new [] { "CreditCardNumber" }, maxDepth: 2);
e.Event.Tags.Add("Order");
e.Event.MarkAsCritical();
e.Event.SetUserIdentity(user.EmailAddress);
}Exceptionless can be combined with logging libraries such as NLog or Log4Net for more detailed log capture, and for high‑throughput scenarios you can enable in‑memory storage with ExceptionlessClient.Default.Configuration.UseInMemoryStorage(); .
In summary, the article demonstrates how to set up Exceptionless, integrate it into an ASP.NET Core application, send various event types, enrich events with metadata, and view the collected error information through the dashboard.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.