Skip to content

Commit

Permalink
Returning back Serilog
Browse files Browse the repository at this point in the history
Switching to vps2
  • Loading branch information
Aragas committed Feb 21, 2024
1 parent 8eb4ea2 commit 1819ef4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 43 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deploy-self-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:
runs-on: ubuntu-latest
environment:
name: 'self-hosted-backend'
url: 'https://vps-sitenexusmods.aragas.org'
url: 'https://vps2-sitenexusmods.aragas.org'
steps:
- name: multiple command
uses: appleboy/ssh-action@master
with:
#host: ${{ secrets.HOST }}
host: ${{ secrets.HOST_2 }}
host: ${{ secrets.HOST_3 }}
#username: ${{ secrets.USERNAME }}
username: ${{ secrets.USERNAME_2 }}
username: ${{ secrets.USERNAME_3 }}
#password: ${{ secrets.PASSWORD }}
password: ${{ secrets.PASSWORD_2 }}
password: ${{ secrets.PASSWORD_3 }}
#port: ${{ secrets.PORT }}
port: ${{ secrets.PORT_2 }}
port: ${{ secrets.PORT_3 }}
script: |
docker image pull ghcr.io/butr/sitenexusmods2;
docker stack deploy --prune --resolve-image always -c /deploy/sitenexusmods2/docker-compose.yml sitenexusmods2;
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Backend": {
"Endpoint": "https://vps-sitenexusmods.aragas.org/"
"Endpoint": "https://vps2-sitenexusmods.aragas.org/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.2" />
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Nerdbank.Streams" Version="2.10.72" />
<PackageReference Include="Npgsql" Version="8.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
Expand All @@ -53,6 +52,11 @@
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.8.1" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.8.1" />
<PackageReference Include="RateLimiter" Version="2.2.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.OpenTelemetry" Version="2.0.0-dev-00270" />
<PackageReference Include="SharpCompress" Version="0.36.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
Expand Down
73 changes: 39 additions & 34 deletions src/BUTR.Site.NexusMods.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Npgsql;

using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.ResourceDetectors.Container;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

using Quartz;

using Serilog;
using Serilog.Events;

using System;
using System.Threading.Tasks;

Expand All @@ -35,22 +36,41 @@ private static void PreBulkSaveChanges(DbContext context)

public static async Task Main(string[] args)
{
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkInsert = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkDelete = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkMerge = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkUpdate = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSynchronize = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSaveChanges = PreBulkSaveChanges;
Z.EntityFramework.Extensions.EntityFrameworkManager.ContextFactory = context => context switch
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateBootstrapLogger();

try
{
AppDbContextRead appDbContextRead => appDbContextRead.New(),
AppDbContextWrite appDbContextWrite => appDbContextWrite.New(),
_ => null
};
Log.Information("Starting web application");

Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkInsert = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkDelete = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkMerge = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkUpdate = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSynchronize = PreBulkOperation;
Z.EntityFramework.Extensions.EntityFrameworkManager.PreBulkSaveChanges = PreBulkSaveChanges;
Z.EntityFramework.Extensions.EntityFrameworkManager.ContextFactory = context => context switch
{
AppDbContextRead appDbContextRead => appDbContextRead.New(),
AppDbContextWrite appDbContextWrite => appDbContextWrite.New(),
_ => null
};

var host = CreateHostBuilder(args).Build();
var host = CreateHostBuilder(args).Build();

await host.SeedDbContext<BaseAppDbContext>().RunAsync();
await host.SeedDbContext<BaseAppDbContext>().RunAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
await Log.CloseAndFlushAsync();
}
}

public static IHostBuilder CreateHostBuilder(string[] args) => Host
Expand Down Expand Up @@ -139,25 +159,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host
{
webBuilder.UseStartup<Startup>();
})
.ConfigureLogging((ctx, builder) =>
.UseSerilog((context, services, configuration) =>
{
var oltpSection = ctx.Configuration.GetSection("Oltp");
if (oltpSection == null!) return;
var loggingEndpoint = oltpSection.GetValue<string>("LoggingEndpoint");
if (loggingEndpoint is null) return;
var loggingProtocol = oltpSection.GetValue<OtlpExportProtocol>("LoggingProtocol");
builder.AddOpenTelemetry(o =>
{
o.IncludeScopes = true;
o.ParseStateValues = true;
o.IncludeFormattedMessage = true;
o.AddOtlpExporter((options, processorOptions) =>
{
options.Endpoint = new Uri(loggingEndpoint);
options.Protocol = loggingProtocol;
});
});
configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services);
});
}
20 changes: 18 additions & 2 deletions src/BUTR.Site.NexusMods.Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
{
"Serilog": {
"Enrich": [
"FromLogContext"
],
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{ "Name": "Console" }
]
}
}
]
},

"Logging": {
"LogLevel": {
"Default": "Information",
Expand All @@ -8,12 +24,12 @@
},

"CrashReporter": {
"Endpoint": "https://report.butr.link/",
"Endpoint": "https://report.butr.link/"
},

"NexusMods": {
"Endpoint": "https://nexusmods.com/",
"APIEndpoint": "https://api.nexusmods.com/",
"APIEndpoint": "https://api.nexusmods.com/"
},

"DepotDownloader": {
Expand Down

0 comments on commit 1819ef4

Please sign in to comment.