Updated log location for all services (#113)

This commit is contained in:
Leendert de Borst
2024-07-26 22:22:19 +02:00
parent ad8ceff2a8
commit d8cfdc2123
6 changed files with 22 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ jobs:
# Test if the service on localhost:80 responds
http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:80)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with 200 OK"
echo "Service did not respond with 200 OK. Check if client app is configured correctly."
exit 1
else
echo "Service responded with 200 OK"
@@ -43,7 +43,7 @@ jobs:
# Test if the service on localhost:81 responds
http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:81)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with expected 200 OK. Check if all DB migrations are applied."
echo "Service did not respond with expected 200 OK. Check if WebApi is configured correctly."
exit 1
else
echo "Service responded with $http_code"
@@ -57,3 +57,13 @@ jobs:
else
echo "SmtpService responded on port 2525"
fi
- name: Test if localhost:8080 (Admin) responds
run: |
# Test if the service on localhost:8080 responds
http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with expected 200 OK. Check if admin app is configured correctly."
exit 1
else
echo "Service responded with $http_code"
fi

View File

@@ -8,6 +8,7 @@ services:
- "8080:8082"
volumes:
- ./database:/database
- ./logs:/logs
restart: always
env_file:
- .env
@@ -31,6 +32,7 @@ services:
- "81:8081"
volumes:
- ./database:/database
- ./logs:/logs
env_file:
- .env
restart: always
@@ -45,6 +47,7 @@ services:
- "587:587"
volumes:
- ./database:/database
- ./logs:/logs
env_file:
- .env
restart: always

View File

@@ -22,7 +22,7 @@ using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../logs");
// Create global config object, get values from environment variables.
Config config = new Config();

View File

@@ -23,7 +23,7 @@ using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../logs");
builder.Services.AddSingleton<ITimeProvider, SystemTimeProvider>();
builder.Services.AddScoped<TimeValidationJwtBearerEvents>();

View File

@@ -22,7 +22,7 @@ using AliasVault.WorkerStatus.ServiceExtensions;
var builder = Host.CreateApplicationBuilder(args);
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../../logs");
// Create global config object, get values from environment variables.
Config config = new Config();

View File

@@ -27,8 +27,9 @@ public static class LoggingConfiguration
/// <param name="services">IServiceCollection.</param>
/// <param name="configuration">IConfiguration.</param>
/// <param name="applicationName">The application name to include in the log.</param>
/// <param name="logFolder">The folder to log to.</param>
/// <returns>IServiceCollection instance.</returns>
public static IServiceCollection ConfigureLogging(this IServiceCollection services, IConfiguration configuration, string applicationName)
public static IServiceCollection ConfigureLogging(this IServiceCollection services, IConfiguration configuration, string applicationName, string logFolder = "logs/")
{
services.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
@@ -42,12 +43,12 @@ public static class LoggingConfiguration
// Log everything to a file.
.WriteTo.Logger(lc => lc
.WriteTo.File($"logs/{applicationName}-log-.txt", rollingInterval: RollingInterval.Day))
.WriteTo.File($"{logFolder}/{applicationName}-log-.txt", rollingInterval: RollingInterval.Day))
// Log all errors and above to a separate file.
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(evt => evt.Level >= LogEventLevel.Error)
.WriteTo.File($"logs/{applicationName}-error-.txt", rollingInterval: RollingInterval.Day))
.WriteTo.File($"{logFolder}/{applicationName}-error-.txt", rollingInterval: RollingInterval.Day))
// Log all warning and above to database via EF core except for Microsoft.EntityFrameworkCore logs
// as this would create a loop.