Merge pull request #202 from Moonlight-Panel/AddSentrySupport
Added new sentry support
This commit is contained in:
@@ -46,6 +46,8 @@
|
|||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
||||||
<PackageReference Include="QRCoder" Version="1.4.3" />
|
<PackageReference Include="QRCoder" Version="1.4.3" />
|
||||||
<PackageReference Include="RestSharp" Version="109.0.0-preview.1" />
|
<PackageReference Include="RestSharp" Version="109.0.0-preview.1" />
|
||||||
|
<PackageReference Include="Sentry.AspNetCore" Version="3.33.1" />
|
||||||
|
<PackageReference Include="Sentry.Serilog" Version="3.33.1" />
|
||||||
<PackageReference Include="Serilog" Version="3.0.0" />
|
<PackageReference Include="Serilog" Version="3.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.1-dev-00910" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.1-dev-00910" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00947" />
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00947" />
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ using Moonlight.App.Services.Notifications;
|
|||||||
using Moonlight.App.Services.Sessions;
|
using Moonlight.App.Services.Sessions;
|
||||||
using Moonlight.App.Services.Statistics;
|
using Moonlight.App.Services.Statistics;
|
||||||
using Moonlight.App.Services.SupportChat;
|
using Moonlight.App.Services.SupportChat;
|
||||||
|
using Sentry;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
using Serilog.Sinks.SystemConsole.Themes;
|
using Serilog.Sinks.SystemConsole.Themes;
|
||||||
|
|
||||||
namespace Moonlight
|
namespace Moonlight
|
||||||
@@ -40,24 +42,62 @@ namespace Moonlight
|
|||||||
{
|
{
|
||||||
// This will also copy all default config files
|
// This will also copy all default config files
|
||||||
var configService = new ConfigService(new StorageService());
|
var configService = new ConfigService(new StorageService());
|
||||||
|
var shouldUseSentry = configService
|
||||||
|
.GetSection("Moonlight")
|
||||||
|
.GetSection("Sentry")
|
||||||
|
.GetValue<bool>("Enable");
|
||||||
|
|
||||||
if (configService.DebugMode)
|
if (configService.DebugMode)
|
||||||
{
|
{
|
||||||
Log.Logger = new LoggerConfiguration()
|
if (shouldUseSentry)
|
||||||
.MinimumLevel.Verbose()
|
{
|
||||||
.Enrich.FromLogContext()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.WriteTo.Console(
|
.MinimumLevel.Verbose()
|
||||||
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
|
.Enrich.FromLogContext()
|
||||||
.CreateLogger();
|
.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
|
else
|
||||||
{
|
{
|
||||||
Log.Logger = new LoggerConfiguration()
|
if (shouldUseSentry)
|
||||||
.MinimumLevel.Information()
|
{
|
||||||
.Enrich.FromLogContext()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.WriteTo.Console(
|
.MinimumLevel.Information()
|
||||||
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}")
|
.Enrich.FromLogContext()
|
||||||
.CreateLogger();
|
.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()}");
|
Logger.Info($"Working dir: {Directory.GetCurrentDirectory()}");
|
||||||
@@ -89,6 +129,21 @@ namespace Moonlight
|
|||||||
.AddCheck<NodeHealthCheck>("Nodes")
|
.AddCheck<NodeHealthCheck>("Nodes")
|
||||||
.AddCheck<DaemonHealthCheck>("Daemons");
|
.AddCheck<DaemonHealthCheck>("Daemons");
|
||||||
|
|
||||||
|
// Sentry
|
||||||
|
if (shouldUseSentry)
|
||||||
|
{
|
||||||
|
builder.WebHost.UseSentry(options =>
|
||||||
|
{
|
||||||
|
options.Dsn = configService
|
||||||
|
.GetSection("Moonlight")
|
||||||
|
.GetSection("Sentry")
|
||||||
|
.GetValue<string>("Dsn");
|
||||||
|
|
||||||
|
options.Debug = configService.DebugMode;
|
||||||
|
options.DiagnosticLevel = SentryLevel.Warning;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Databases
|
// Databases
|
||||||
builder.Services.AddDbContext<DataContext>();
|
builder.Services.AddDbContext<DataContext>();
|
||||||
|
|
||||||
@@ -203,6 +258,12 @@ namespace Moonlight
|
|||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sentry
|
||||||
|
if (shouldUseSentry)
|
||||||
|
{
|
||||||
|
app.UseSentryTracing();
|
||||||
|
}
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseWebSockets();
|
app.UseWebSockets();
|
||||||
|
|||||||
@@ -92,6 +92,10 @@
|
|||||||
"Url": "link-to-google.page",
|
"Url": "link-to-google.page",
|
||||||
"MinRating": 4,
|
"MinRating": 4,
|
||||||
"DaysSince": 5
|
"DaysSince": 5
|
||||||
|
},
|
||||||
|
"Sentry": {
|
||||||
|
"Enable": false,
|
||||||
|
"Dsn": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user