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