Sets Serilog file configuration for all setups and environments

This commit is contained in:
BinaryAlley committed 2024-11-06 17:04:21 +02:00
1 parent 6022800776
commit 181c681813
9 files changed
+31 -13

No files matched your search

+1 -3
View File
@@ -1,9 +1,9 @@
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
RUN mkdir /logs && chown -R app:app /logs
USER app
WORKDIR /app
EXPOSE 5214
EXPOSE 7057
# ==== Stage 1: Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
@@ -50,9 +50,7 @@ WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_HTTP_PORTS=5214
ENV ASPNETCORE_HTTPS_PORTS=7057
EXPOSE 5214
EXPOSE 7057
ENTRYPOINT ["dotnet", "Lumina.Presentation.Api.dll"]
# to build this Docker image, run the following command from the root of the project (location of the .sln file):
@@ -33,6 +33,7 @@
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.AspnetcoreHttpcontext" Version="1.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
</ItemGroup>
+10 -1
View File
@@ -8,6 +8,7 @@ using Lumina.Domain.Common.DependencyInjection;
using Lumina.Infrastructure.Common.DependencyInjection;
using Lumina.Presentation.Api.Common.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -45,10 +46,18 @@ public class Program
// determine log path based on environment
string logPath;
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true")
{
logPath = Environment.GetEnvironmentVariable("LOG_PATH") ?? "/logs"; // use docker volume path
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5214); // HTTP only
});
}
else
logPath = Path.Combine(AppContext.BaseDirectory, "logs"); // use local binary path
Directory.CreateDirectory(logPath);
if (!logPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
logPath = logPath += Path.DirectorySeparatorChar;
// set environment variable for Serilog configuration
Environment.SetEnvironmentVariable("LOG_PATH", logPath);
@@ -58,7 +67,7 @@ public class Program
.ReadFrom.Services(services)
.Enrich.FromLogContext();
});
string? aa = builder.Configuration.GetValue<string>("LOG_PATH");
WebApplication app = builder.Build();
app.UseSerilogRequestLogging();
+2 -1
View File
@@ -1,5 +1,6 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
@@ -20,7 +21,7 @@
{
"Name": "File",
"Args": {
"path": "${LOG_PATH}/lumina_api_.log",
"path": "%LOG_PATH%lumina_api_.log",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
"retainedFileCountLimit": 7,