Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using EdFi.Security.DataAccess.Contexts;
using FluentValidation;
using FluentValidation.AspNetCore;
using log4net;
using log4net.Config;
using Microsoft.AspNetCore.Http.Json;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -169,10 +171,6 @@ public static void AddServices(this WebApplicationBuilder webApplicationBuilder)
});
});

// Logging
var loggingOptions = config.GetSection("Log4NetCore").Get<Log4NetProviderOptions>();
webApplicationBuilder.Logging.AddLog4Net(loggingOptions);

// Fluent validation
webApplicationBuilder
.Services.AddValidatorsFromAssembly(assembly)
Expand Down Expand Up @@ -213,6 +211,30 @@ public static void AddServices(this WebApplicationBuilder webApplicationBuilder)
webApplicationBuilder.Services.AddTransient<ITenantsService, TenantService>();
}

public static void AddLoggingServices(this WebApplicationBuilder webApplicationBuilder)
{
ConfigurationManager config = webApplicationBuilder.Configuration;

// Remove all default logging providers (Console, Debug, etc.)
webApplicationBuilder.Logging.ClearProviders();

// Initialize log4net early so we can use it in Program.cs
var log4netConfigFileName = webApplicationBuilder.Configuration.GetValue<string>("Log4NetCore:Log4NetConfigFileName");
if (!string.IsNullOrEmpty(log4netConfigFileName))
{
var log4netConfigPath = Path.Combine(AppContext.BaseDirectory, log4netConfigFileName);
if (File.Exists(log4netConfigPath))
{
var log4netConfig = new FileInfo(log4netConfigPath);
XmlConfigurator.Configure(LogManager.GetRepository(), log4netConfig);
}
}

// Important to display messages based on the Logging section in appsettings.json
var loggingOptions = config.GetSection("Log4NetCore").Get<Log4NetProviderOptions>();
webApplicationBuilder.Logging.AddLog4Net(loggingOptions);
}

private static void EnableMultiTenancySupport(this WebApplicationBuilder webApplicationBuilder)
{
webApplicationBuilder.Services.AddTransient<
Expand Down
11 changes: 1 addition & 10 deletions Application/EdFi.Ods.AdminApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
var builder = WebApplication.CreateBuilder(args);

// Initialize log4net early so we can use it in Program.cs
var log4netConfigFileName = builder.Configuration.GetValue<string>("Log4NetCore:Log4NetConfigFileName");
if (!string.IsNullOrEmpty(log4netConfigFileName))
{
var log4netConfigPath = Path.Combine(AppContext.BaseDirectory, log4netConfigFileName);
if (File.Exists(log4netConfigPath))
{
var log4netConfig = new FileInfo(log4netConfigPath);
XmlConfigurator.Configure(LogManager.GetRepository(), log4netConfig);
}
}
builder.AddLoggingServices();

// logging
var _logger = LogManager.GetLogger("Program");
Expand Down
Loading