57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
namespace Common.UI.Infrastructure
|
|
{
|
|
using Common.Hardware.SIRT;
|
|
|
|
using NLog;
|
|
using NLog.Config;
|
|
using NLog.Targets;
|
|
|
|
using System;
|
|
using System.IO;
|
|
|
|
internal class AppHost
|
|
{
|
|
public static readonly ILogger NLogger = CreateSIRTLogger();
|
|
public static readonly SIRTHub SIRTHub = CreateSIRTFactory();
|
|
|
|
public static string GetSetting(string key)
|
|
=> Appsettings.GetSetting(key);
|
|
|
|
private static ILogger CreateSIRTLogger()
|
|
{
|
|
var dll = new FileInfo(typeof(AppHost).Assembly.Location);
|
|
var name = "NLogs";
|
|
var nlogs = dll.Directory.CreateSubdirectory(name);
|
|
var file = Path.Combine(nlogs.FullName, $"{DateTime.Now:yyyy-MM-dd-HH}.txt");
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
|
LogManager.ThrowConfigExceptions = true;
|
|
LogManager.ThrowExceptions = true;
|
|
LogManager.AutoShutdown = true;
|
|
|
|
LogManager.Configuration.AddTarget(new FileTarget(name)
|
|
{
|
|
CreateDirs = true,
|
|
KeepFileOpen = true,
|
|
FileName = file,
|
|
Layout = "${message}"
|
|
});
|
|
|
|
LogManager.Configuration.AddRule(LogLevel.Trace, LogLevel.Fatal, name);
|
|
LogManager.LogFactory.ReconfigExistingLoggers(true);
|
|
LogManager.ReconfigExistingLoggers(true);
|
|
|
|
return LogManager.GetLogger(name);
|
|
}
|
|
|
|
private static SIRTHub CreateSIRTFactory()
|
|
{
|
|
var sirtHub = new SIRTHub();
|
|
|
|
SIRTLogger.Message += NLogger.Debug;
|
|
|
|
return sirtHub;
|
|
}
|
|
}
|
|
}
|