|
@@ -1,4 +1,4 @@
|
|
|
-using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
@@ -16,14 +16,42 @@ namespace WebChallenge
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
|
|
|
|
|
+ //public static void Main(string[] args)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // XmlDocument log4netConfig = new XmlDocument();
|
|
|
|
|
+ // log4netConfig.Load(File.OpenRead("log4net.config"));
|
|
|
|
|
+ // var repo = log4net.LogManager.CreateRepository(
|
|
|
|
|
+ // Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
|
|
|
|
|
+
|
|
|
|
|
+ // log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
|
|
|
|
|
+
|
|
|
|
|
+ // log.Info("Application - Main is invoked");
|
|
|
|
|
+
|
|
|
|
|
+ // CreateHostBuilder(args).Build().Run();
|
|
|
|
|
+ //}
|
|
|
public static void Main(string[] args)
|
|
public static void Main(string[] args)
|
|
|
{
|
|
{
|
|
|
- XmlDocument log4netConfig = new XmlDocument();
|
|
|
|
|
- log4netConfig.Load(File.OpenRead("log4net.config"));
|
|
|
|
|
- var repo = log4net.LogManager.CreateRepository(
|
|
|
|
|
- Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
|
|
|
|
|
|
|
+ // 1. Xác định đường dẫn tuyệt đối đến file config
|
|
|
|
|
+ string configPath = Path.Combine(AppContext.BaseDirectory, "log4net.config");
|
|
|
|
|
+
|
|
|
|
|
+ // Kiểm tra xem file có tồn tại không trước khi load để tránh crash ứng dụng
|
|
|
|
|
+ if (!File.Exists(configPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ // Bạn có thể log ra console hoặc event log của windows ở đây nếu muốn
|
|
|
|
|
+ Console.WriteLine($"Không tìm thấy file cấu hình tại: {configPath}");
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ XmlDocument log4netConfig = new XmlDocument();
|
|
|
|
|
+ using (var fs = File.OpenRead(configPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ log4netConfig.Load(fs);
|
|
|
|
|
+ var repo = log4net.LogManager.CreateRepository(
|
|
|
|
|
+ Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
|
|
|
|
|
|
|
|
- log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
|
|
|
|
|
|
|
+ log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
log.Info("Application - Main is invoked");
|
|
log.Info("Application - Main is invoked");
|
|
|
|
|
|