2022-07-23 19:23:32 +00:00
|
|
|
|
using log4net;
|
|
|
|
|
using log4net.Appender;
|
|
|
|
|
using log4net.Config;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.Shared
|
|
|
|
|
{
|
|
|
|
|
public class FileLogger
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
static FileLogger()
|
|
|
|
|
{
|
|
|
|
|
// Setup log4Net
|
|
|
|
|
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
|
|
|
|
|
|
|
|
|
// Need to use AppContext.BaseDirectory for Single File Publishing to work
|
|
|
|
|
// https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#api-semantics
|
|
|
|
|
XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(AppContext.BaseDirectory, "log4net.config")));
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (LogManager.GetRepository(Assembly.GetEntryAssembly()).GetAppenders().First() is not RollingFileAppender errorLogAppender)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
errorLogAppender.File = FileIo.GetErrorLogFilePath();
|
|
|
|
|
errorLogAppender.ActivateOptions();
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
//var infoLogAppender = LogManager.GetRepository(Assembly.GetEntryAssembly()).GetAppenders().Skip(1).First() as RollingFileAppender;
|
|
|
|
|
//infoLogAppender.File = FileIo.GetInfoLogFilePath();
|
|
|
|
|
//infoLogAppender.ActivateOptions();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
//var debugLogAppender = LogManager.GetRepository(Assembly.GetEntryAssembly()).GetAppenders().Skip(2).First() as RollingFileAppender;
|
|
|
|
|
//debugLogAppender.File = FileIo.GetDebugLogFilePath();
|
|
|
|
|
//debugLogAppender.ActivateOptions();
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void WriteLog(string message, StatusMessageType messageType)
|
|
|
|
|
{
|
|
|
|
|
switch (messageType)
|
|
|
|
|
{
|
|
|
|
|
case StatusMessageType.Error:
|
|
|
|
|
Log.Error(message);
|
|
|
|
|
break;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
//case StatusMessageType.Info:
|
|
|
|
|
// Log.Info(message);
|
|
|
|
|
// break;
|
|
|
|
|
//case StatusMessageType.Debug:
|
|
|
|
|
// Log.Debug(message);
|
|
|
|
|
// break;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void WriteException(string message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(message, exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|