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 2 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
9 changes: 9 additions & 0 deletions Application/EdFi.Ods.AdminApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
using EdFi.Ods.AdminApi.Features;
using EdFi.Ods.AdminApi.Infrastructure;
using log4net;
using log4net.Config;

var builder = WebApplication.CreateBuilder(args);

// Initialize log4net early so we can use it in Program.cs
var log4netConfigPath = Path.Combine(AppContext.BaseDirectory, "log4net", "log4net.config");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the log4netConfigPath should be read from the appsettings file, which has Log4NetCore.Log4NetConfigFileName in it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to read the log4net config path from Log4NetCore.Log4NetConfigFileName in appsettings.json instead of hardcoding it. The change ensures consistency with the existing configuration pattern used by the Microsoft.Extensions.Logging.Log4Net.AspNetCore integration. Commit: 0b49c6f

if (File.Exists(log4netConfigPath))
{
var log4netConfig = new FileInfo(log4netConfigPath);
XmlConfigurator.Configure(LogManager.GetRepository(), log4netConfig);
}

// logging
var _logger = LogManager.GetLogger("Program");
_logger.Info("Starting Admin API");
Expand Down
2 changes: 1 addition & 1 deletion Application/EdFi.Ods.AdminApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"EdFiApiDiscoveryUrl": "https://api.ed-fi.org/v7.2/api/",
"Log4NetCore": {
"Log4NetConfigFileName": "log4net\\log4net.config"
"Log4NetConfigFileName": "log4net/log4net.config"
},
"Logging": {
"LogLevel": {
Expand Down
6 changes: 3 additions & 3 deletions Application/EdFi.Ods.AdminApi/log4net/log4net.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="${ProgramData}\Ed-Fi-ODS-AdminAPI\Log.txt" />
<file value="logs/Ed-Fi-ODS-AdminAPI-Log.txt" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is truly a better default option.

<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
Expand All @@ -18,7 +18,7 @@
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="TraceAppender" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FileAppender" />
</root>
</log4net>