1- using Microsoft . AspNetCore . Hosting ;
2- using Microsoft . Extensions . Hosting ;
3-
4- namespace Exceptionless . SampleAspNetCore {
5- public class Program {
6- public static void Main ( string [ ] args ) {
7- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
8- }
9-
10- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
11- Host . CreateDefaultBuilder ( args )
12- . ConfigureLogging ( b => {
13- // By default sends warning and error log messages to Exceptionless.
14- // Log levels can be controlled remotely per log source from the Exceptionless app in near real-time.
15- b . AddExceptionless ( ) ;
16- } )
17- . ConfigureWebHostDefaults ( webBuilder => {
18- webBuilder . UseStartup < Startup > ( ) ;
19- } ) ;
20- }
21- }
1+ using Exceptionless ;
2+ using Microsoft . AspNetCore . Builder ;
3+ using Microsoft . Extensions . DependencyInjection ;
4+ using Microsoft . Extensions . Logging ;
5+
6+ var builder = WebApplication . CreateBuilder ( args ) ;
7+
8+ // By default sends warning and error log messages to Exceptionless.
9+ // Log levels can be controlled remotely per log source from the Exceptionless app in near real-time.
10+ builder . Logging . AddExceptionless ( ) ;
11+
12+ // Reads settings from IConfiguration then adds additional configuration from this lambda.
13+ // This also configures ExceptionlessClient.Default, host shutdown queue flushing,
14+ // and automatically registers the Exceptionless IExceptionHandler.
15+ builder . AddExceptionless ( c => c . DefaultData [ "Startup" ] = "heyyy" ) ;
16+ // OR
17+ // builder.AddExceptionless();
18+ // OR
19+ // builder.AddExceptionless("API_KEY_HERE");
20+
21+ // Required: configures the response format for unhandled exceptions (e.g., RFC 7807 Problem Details).
22+ builder . Services . AddProblemDetails ( ) ;
23+
24+ // This is normal ASP.NET Core code.
25+ builder . Services . AddControllers ( ) ;
26+
27+ var app = builder . Build ( ) ;
28+
29+ // Uses the built-in exception handler pipeline, with Exceptionless capturing via IExceptionHandler.
30+ app . UseExceptionHandler ( ) ;
31+
32+ // Adds Exceptionless middleware for diagnostics, 404 tracking, and queue processing.
33+ app . UseExceptionless ( ) ;
34+
35+ app . MapControllers ( ) ;
36+
37+ app . Run ( ) ;
0 commit comments