22using Microsoft . Extensions . Configuration ;
33using Microsoft . Extensions . DependencyInjection ;
44using Microsoft . Extensions . Hosting ;
5+ using Sentry ;
56using Serilog ;
67
78namespace EnvironmentSetup ;
@@ -12,12 +13,29 @@ public static class DmsServiceExtensions
1213 /// Configures Serilog logging for all DMS applications.
1314 /// Works for both ASP.NET Core apps and Worker Services.
1415 /// Reads configuration from appsettings.json Serilog section.
16+ /// Integrates with Sentry for error tracking.
1517 /// </summary>
1618 public static IHostApplicationBuilder UseDmsSerilog ( this IHostApplicationBuilder builder )
1719 {
20+ var sentryDsn = builder . Configuration [ "Sentry:Dsn" ] ;
21+
22+ if ( ! string . IsNullOrWhiteSpace ( sentryDsn ) )
23+ {
24+ SentrySdk . Init ( options =>
25+ {
26+ options . Dsn = sentryDsn ;
27+ options . Environment = builder . Environment . EnvironmentName ;
28+ options . TracesSampleRate = 1.0 ;
29+ options . AttachStacktrace = true ;
30+ options . SendDefaultPii = false ;
31+ options . AutoSessionTracking = true ;
32+ } ) ;
33+ }
34+
1835 builder . Services . AddSerilog ( config => config
1936 . ReadFrom . Configuration ( builder . Configuration )
20- . WriteTo . File ( Path . Combine ( "logs" , "fatal.txt" ) , Serilog . Events . LogEventLevel . Fatal ) ) ;
37+ . WriteTo . File ( Path . Combine ( "logs" , "fatal.txt" ) , Serilog . Events . LogEventLevel . Fatal )
38+ . WriteTo . Sentry ( ) ) ;
2139
2240 return builder ;
2341 }
0 commit comments