Compare commits
1 Commits
v1.0.33-ma
...
v1.0.34-ma
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dd854a159a |
@@ -61,9 +61,6 @@ namespace Torch.Server
|
|||||||
|
|
||||||
if (File.Exists(oldTorchCfg))
|
if (File.Exists(oldTorchCfg))
|
||||||
File.Move(oldTorchCfg, torchCfg, true);
|
File.Move(oldTorchCfg, torchCfg, true);
|
||||||
|
|
||||||
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
|
||||||
TorchLogManager.SetConfiguration(new XmlLoggingConfiguration(newNlog));
|
|
||||||
|
|
||||||
var config = Persistent<TorchConfig>.Load(torchCfg);
|
var config = Persistent<TorchConfig>.Load(torchCfg);
|
||||||
config.Data.InstanceName = instanceName;
|
config.Data.InstanceName = instanceName;
|
||||||
@@ -76,15 +73,18 @@ namespace Torch.Server
|
|||||||
|
|
||||||
var handler = new UnhandledExceptionHandler(config.Data, isService);
|
var handler = new UnhandledExceptionHandler(config.Data, isService);
|
||||||
AppDomain.CurrentDomain.UnhandledException += handler.OnUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += handler.OnUnhandledException;
|
||||||
|
|
||||||
|
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
|
||||||
|
TorchLogManager.RegisterTargets(Environment.GetEnvironmentVariable("TORCH_LOG_EXTENSIONS_PATH") ??
|
||||||
|
Path.Combine(instancePath, "LoggingExtensions"));
|
||||||
|
|
||||||
|
TorchLogManager.SetConfiguration(new XmlLoggingConfiguration(newNlog));
|
||||||
|
|
||||||
var initializer = new Initializer(workingDir, config);
|
var initializer = new Initializer(workingDir, config);
|
||||||
if (!initializer.Initialize(args))
|
if (!initializer.Initialize(args))
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
|
|
||||||
TorchLauncher.Launch(workingDir, binDir);
|
TorchLauncher.Launch(workingDir, binDir);
|
||||||
TorchLogManager.SetConfiguration(TorchLogManager.Configuration,
|
|
||||||
Environment.GetEnvironmentVariable("TORCH_LOG_EXTENSIONS_PATH") ??
|
|
||||||
Path.Combine(instancePath, "LoggingExtensions"));
|
|
||||||
|
|
||||||
CopyNative(binDir);
|
CopyNative(binDir);
|
||||||
initializer.Run(isService, instanceName, instancePath);
|
initializer.Run(isService, instanceName, instancePath);
|
||||||
|
@@ -1,47 +1,41 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
|
using NLog.Targets;
|
||||||
|
|
||||||
namespace Torch.Utils;
|
namespace Torch.Utils;
|
||||||
|
|
||||||
public static class TorchLogManager
|
public static class TorchLogManager
|
||||||
{
|
{
|
||||||
private static AssemblyLoadContext LoadContext;
|
private static AssemblyLoadContext LoadContext = new("TorchLog");
|
||||||
|
|
||||||
public static LoggingConfiguration Configuration { get; private set; }
|
public static LoggingConfiguration Configuration { get; private set; }
|
||||||
|
|
||||||
public static void SetConfiguration(LoggingConfiguration configuration, string extensionsDir = null)
|
public static void SetConfiguration(LoggingConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
LogManager.Setup()
|
LogManager.Configuration = configuration;
|
||||||
.SetupExtensions(builder =>
|
|
||||||
{
|
|
||||||
if (extensionsDir is null || !Directory.Exists(extensionsDir))
|
|
||||||
return;
|
|
||||||
if (LoadContext is null)
|
|
||||||
{
|
|
||||||
LoadContext = new("TorchLog");
|
|
||||||
foreach (var file in Directory.EnumerateFiles(extensionsDir, "*.dll", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
builder.RegisterAssembly(LoadContext.LoadFromAssemblyPath(file));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach (var assembly in LoadContext.Assemblies)
|
|
||||||
{
|
|
||||||
builder.RegisterAssembly(assembly);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.SetupLogFactory(builder => builder.SetThrowConfigExceptions(true))
|
|
||||||
.LoadConfiguration(configuration);
|
|
||||||
LogManager.ReconfigExistingLoggers();
|
LogManager.ReconfigExistingLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RegisterTargets(string dir)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(dir)) return;
|
||||||
|
|
||||||
|
foreach (var type in Directory.EnumerateFiles(dir, "*.dll").Select(LoadContext.LoadFromAssemblyPath)
|
||||||
|
.SelectMany(b => b.ExportedTypes)
|
||||||
|
.Where(b => b.GetCustomAttribute<TargetAttribute>() is { }))
|
||||||
|
{
|
||||||
|
Target.Register(type.GetCustomAttribute<TargetAttribute>()!.Name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void RestoreGlobalConfiguration()
|
public static void RestoreGlobalConfiguration()
|
||||||
{
|
{
|
||||||
LogManager.Configuration = Configuration;
|
SetConfiguration(Configuration);
|
||||||
LogManager.ReconfigExistingLoggers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user