mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 12:54:20 +01:00
Added logging & DBContextFactory implementation. Updated 'DotBased' Module
This commit is contained in:
parent
1d75dd6da0
commit
5bb96a48ee
2
DotBased
2
DotBased
|
@ -1 +1 @@
|
||||||
Subproject commit c1d18d5b47f3dec81c5c153b8a66daf921b3eeef
|
Subproject commit 03daea46e78dfa97d3e4f85fa8035fef5c5ed446
|
|
@ -1,13 +1,25 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SharpRSS.Blazor.Components;
|
using SharpRSS.Blazor.Components;
|
||||||
|
using SharpRSS.Business;
|
||||||
|
using SharpRSS.Data;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.UseSRSS();
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
var contextFactory = app.Services.GetService<IDbContextFactory<SRSSContext>>();
|
||||||
|
if (contextFactory != null)
|
||||||
|
{
|
||||||
|
await using var context = await contextFactory.CreateDbContextAsync();
|
||||||
|
context.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|
BIN
SharpRSS.Blazor/SRSS.db
Normal file
BIN
SharpRSS.Blazor/SRSS.db
Normal file
Binary file not shown.
|
@ -1,8 +1,46 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Database":
|
||||||
"LogLevel": {
|
{
|
||||||
"Default": "Information",
|
"Server": "SQLite",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Connection": "Data Source=SRSS.db"
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Debug",
|
||||||
|
"Override": {
|
||||||
|
"System": "Information",
|
||||||
|
"Microsoft": "Debug",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Debug",
|
||||||
|
"Microsoft.AspNetCore": "Debug",
|
||||||
|
"Microsoft.AspNetCore.Authentication": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Args":
|
||||||
|
{
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} - {Caller}->{Assembly}] | {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args":
|
||||||
|
{
|
||||||
|
"path": "Logs/Debug/log_.log",
|
||||||
|
"RollingInterval": "Day",
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} - {Caller}->{Assembly}] | {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Destructure": [
|
||||||
|
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } },
|
||||||
|
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } },
|
||||||
|
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } }
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "SharpRSS"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,46 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Database":
|
||||||
"LogLevel": {
|
{
|
||||||
|
"Server": "SQLite",
|
||||||
|
"Connection": "Data Source=SRSS.db"
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Override": {
|
||||||
|
"System": "Information",
|
||||||
|
"Microsoft": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"Microsoft.AspNetCore.Authentication": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Args":
|
||||||
|
{
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} - {Caller}->{Assembly}] | {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args":
|
||||||
|
{
|
||||||
|
"path": "Logs/Debug/log_.log",
|
||||||
|
"RollingInterval": "Day",
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} - {Caller}->{Assembly}] | {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Destructure": [
|
||||||
|
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } },
|
||||||
|
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } },
|
||||||
|
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } }
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "SharpRSS"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
|
|
|
@ -1,6 +1,59 @@
|
||||||
|
using DotBased.Logging;
|
||||||
|
using DotBased.Logging.Serilog;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
using Serilog;
|
||||||
|
using SharpRSS.Core.Configuration;
|
||||||
|
using SharpRSS.Data;
|
||||||
|
|
||||||
namespace SharpRSS.Business;
|
namespace SharpRSS.Business;
|
||||||
|
|
||||||
public static class DependencyInjection
|
public static class DependencyInjection
|
||||||
{
|
{
|
||||||
|
public static WebApplicationBuilder UseSRSS(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
// Logging (serilog)
|
||||||
|
var serilogConfig = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).UseBasedExtension();
|
||||||
|
Log.Logger = serilogConfig.CreateLogger();
|
||||||
|
|
||||||
|
LogService.AddLogAdapter(new BasedSerilogAdapter(Log.Logger));
|
||||||
|
var logger = LogService.RegisterLogger(typeof(DependencyInjection));
|
||||||
|
|
||||||
|
builder.Logging.ClearProviders();
|
||||||
|
builder.Logging.AddSerilog();
|
||||||
|
|
||||||
|
// EF Core DbContextFactory
|
||||||
|
builder.Services.AddDbContextFactory<SRSSContext>(options =>
|
||||||
|
{
|
||||||
|
var dbSettings = new DatabaseSettings();
|
||||||
|
builder.Configuration.GetSection(DatabaseSettings.Configuration).Bind(dbSettings);
|
||||||
|
options.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuted, LogLevel.Debug)));
|
||||||
|
switch (dbSettings.Server.ToUpper())
|
||||||
|
{
|
||||||
|
case "SQLITE":
|
||||||
|
logger.Information("Configuring SQLite context...");
|
||||||
|
options.UseSqlite(dbSettings.Connection);
|
||||||
|
break;
|
||||||
|
case "MARIADB":
|
||||||
|
logger.Information("Configuring MariaDB context...");
|
||||||
|
var srvVersion = ServerVersion.AutoDetect(dbSettings.Connection);
|
||||||
|
logger.Information("Server found, version: {SrvVersion}", srvVersion.Version.Build);
|
||||||
|
options.UseMySql(dbSettings.Connection, srvVersion);
|
||||||
|
break;
|
||||||
|
case "MSSQL":
|
||||||
|
logger.Information("Configuring MSSQL context...");
|
||||||
|
options.UseSqlServer(dbSettings.Connection);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("No database server type specified in settings!, supported types: 'SQLite' 'MariaDB' 'MSSQL'");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO: Services, Auth, Settings
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -13,4 +13,27 @@
|
||||||
<ProjectReference Include="..\SharpRSS.Data\SharpRSS.Data.csproj" />
|
<ProjectReference Include="..\SharpRSS.Data\SharpRSS.Data.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.AspNetCore">
|
||||||
|
<HintPath>..\..\..\..\..\usr\lib64\dotnet\shared\Microsoft.AspNetCore.App\8.0.4\Microsoft.AspNetCore.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\..\usr\lib64\dotnet\shared\Microsoft.AspNetCore.App\8.0.4\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\..\usr\lib64\dotnet\shared\Microsoft.AspNetCore.App\8.0.4\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
|
||||||
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
9
SharpRSS.Core/Configuration/DatabaseSettings.cs
Normal file
9
SharpRSS.Core/Configuration/DatabaseSettings.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace SharpRSS.Core.Configuration;
|
||||||
|
|
||||||
|
public class DatabaseSettings
|
||||||
|
{
|
||||||
|
public const string Configuration = "Database";
|
||||||
|
|
||||||
|
public string Server { get; set; } = string.Empty;
|
||||||
|
public string Connection { get; set; } = string.Empty;
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace SharpRSS.Data;
|
namespace SharpRSS.Data;
|
||||||
|
|
||||||
public class SRSSContext
|
public sealed class SRSSContext : DbContext
|
||||||
{
|
{
|
||||||
public SRSSContext()
|
public SRSSContext(DbContextOptions<SRSSContext> options) : base(options)
|
||||||
{
|
{
|
||||||
|
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||||
|
ChangeTracker.LazyLoadingEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,4 +10,8 @@
|
||||||
<ProjectReference Include="..\SharpRSS.Core\SharpRSS.Core.csproj" />
|
<ProjectReference Include="..\SharpRSS.Core\SharpRSS.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user