Loggin
This commit is contained in:
+5
-1
@@ -28,9 +28,11 @@ services:
|
||||
- DB_PROVIDER=PostgreSQL
|
||||
- ConnectionStrings__DefaultConnection=Host=db;Database=timetracker;Username=timetracker_user;Password=SecretPassword123;
|
||||
- EnableHttpsRedirect=false
|
||||
- TIMETRACKER_LOG_DIR=/app/logs
|
||||
- TenantSettings__BaseDomain=timetracker.marc-wieland.de
|
||||
volumes:
|
||||
- dpkeys:/home/app/.aspnet/DataProtection-Keys
|
||||
- applogs:/app/logs
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
@@ -38,4 +40,6 @@ volumes:
|
||||
pgdata:
|
||||
name: timetracker_pgdata
|
||||
dpkeys:
|
||||
name: timetracker_dpkeys
|
||||
name: timetracker_dpkeys
|
||||
applogs:
|
||||
name: timetracker_logs
|
||||
@@ -27,15 +27,18 @@ COPY --from=build /app/publish .
|
||||
|
||||
# Directory for SQLite database
|
||||
RUN mkdir -p /data
|
||||
RUN mkdir -p /app/logs
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=8080
|
||||
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
|
||||
ENV TIMETRACKER_DB_PATH=/data/timetracker.db
|
||||
ENV TIMETRACKER_LOG_DIR=/app/logs
|
||||
ENV EnableHttpsRedirect=false
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
VOLUME ["/data"]
|
||||
VOLUME ["/app/logs"]
|
||||
|
||||
ENTRYPOINT ["dotnet", "timetracker.Server.dll"]
|
||||
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MudBlazor.Services;
|
||||
using Serilog;
|
||||
using timetracker.Server.Components;
|
||||
using timetracker.Data;
|
||||
using timetracker.Shared;
|
||||
@@ -16,6 +17,24 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
const string SuperAdminUsername = "marc";
|
||||
const string SuperAdminPassword = "123456";
|
||||
|
||||
var logDirectory = Environment.GetEnvironmentVariable("TIMETRACKER_LOG_DIR")
|
||||
?? Path.Combine(builder.Environment.ContentRootPath, "logs");
|
||||
Directory.CreateDirectory(logDirectory);
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File(
|
||||
Path.Combine(logDirectory, "timetracker-.log"),
|
||||
rollingInterval: RollingInterval.Day,
|
||||
retainedFileCountLimit: 14,
|
||||
shared: true,
|
||||
flushToDiskInterval: TimeSpan.FromSeconds(1))
|
||||
.CreateLogger();
|
||||
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
// Add Authentication
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(options =>
|
||||
@@ -132,6 +151,8 @@ else
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.Logger.LogInformation("File logging active. Writing logs to {LogDirectory}", logDirectory);
|
||||
|
||||
// Migrate or Ensure Database Created
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Information"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Information"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.8" />
|
||||
<PackageReference Include="MudBlazor" Version="9.4.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.2" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user