diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj
index c4a6dcab..dec7a172 100644
--- a/Moonlight/Moonlight.csproj
+++ b/Moonlight/Moonlight.csproj
@@ -46,6 +46,8 @@
+
+
diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs
index 697ccdd5..d706fd97 100644
--- a/Moonlight/Program.cs
+++ b/Moonlight/Program.cs
@@ -29,7 +29,9 @@ using Moonlight.App.Services.Notifications;
using Moonlight.App.Services.Sessions;
using Moonlight.App.Services.Statistics;
using Moonlight.App.Services.SupportChat;
+using Sentry;
using Serilog;
+using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
namespace Moonlight
@@ -40,24 +42,62 @@ namespace Moonlight
{
// This will also copy all default config files
var configService = new ConfigService(new StorageService());
+ var shouldUseSentry = configService
+ .GetSection("Moonlight")
+ .GetSection("Sentry")
+ .GetValue("Enable");
if (configService.DebugMode)
{
- Log.Logger = new LoggerConfiguration()
- .MinimumLevel.Verbose()
- .Enrich.FromLogContext()
- .WriteTo.Console(
- outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
- .CreateLogger();
+ if (shouldUseSentry)
+ {
+ Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Verbose()
+ .Enrich.FromLogContext()
+ .WriteTo.Console(
+ outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
+ .WriteTo.Sentry(options =>
+ {
+ options.MinimumBreadcrumbLevel = LogEventLevel.Debug;
+ options.MinimumEventLevel = LogEventLevel.Warning;
+ })
+ .CreateLogger();
+ }
+ else
+ {
+ Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Verbose()
+ .Enrich.FromLogContext()
+ .WriteTo.Console(
+ outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
+ .CreateLogger();
+ }
}
else
{
- Log.Logger = new LoggerConfiguration()
- .MinimumLevel.Information()
- .Enrich.FromLogContext()
- .WriteTo.Console(
- outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
- .CreateLogger();
+ if (shouldUseSentry)
+ {
+ Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Information()
+ .Enrich.FromLogContext()
+ .WriteTo.Console(
+ outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
+ .WriteTo.Sentry(options =>
+ {
+ options.MinimumBreadcrumbLevel = LogEventLevel.Information;
+ options.MinimumEventLevel = LogEventLevel.Warning;
+ })
+ .CreateLogger();
+ }
+ else
+ {
+ Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Information()
+ .Enrich.FromLogContext()
+ .WriteTo.Console(
+ outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
+ .CreateLogger();
+ }
}
Logger.Info($"Working dir: {Directory.GetCurrentDirectory()}");
@@ -66,7 +106,7 @@ namespace Moonlight
var databaseCheckupService = new DatabaseCheckupService(configService);
await databaseCheckupService.Perform();
-
+
var builder = WebApplication.CreateBuilder(args);
// Switch to logging.net injection
@@ -88,6 +128,21 @@ namespace Moonlight
.AddCheck("Database")
.AddCheck("Nodes")
.AddCheck("Daemons");
+
+ // Sentry
+ if (shouldUseSentry)
+ {
+ builder.WebHost.UseSentry(options =>
+ {
+ options.Dsn = configService
+ .GetSection("Moonlight")
+ .GetSection("Sentry")
+ .GetValue("Dsn");
+
+ options.Debug = configService.DebugMode;
+ options.DiagnosticLevel = SentryLevel.Warning;
+ });
+ }
// Databases
builder.Services.AddDbContext();
@@ -203,6 +258,12 @@ namespace Moonlight
app.UseHsts();
}
+ // Sentry
+ if (shouldUseSentry)
+ {
+ app.UseSentryTracing();
+ }
+
app.UseStaticFiles();
app.UseRouting();
app.UseWebSockets();
diff --git a/Moonlight/defaultstorage/configs/config.json b/Moonlight/defaultstorage/configs/config.json
index bc1bc396..ade2ab5b 100644
--- a/Moonlight/defaultstorage/configs/config.json
+++ b/Moonlight/defaultstorage/configs/config.json
@@ -92,6 +92,10 @@
"Url": "link-to-google.page",
"MinRating": 4,
"DaysSince": 5
+ },
+ "Sentry": {
+ "Enable": false,
+ "Dsn": ""
}
}
}
\ No newline at end of file