Compare commits

...

1 Commits

Author SHA1 Message Date
z__
3696f18714 move nlog config to instance and move default to resources 2022-02-04 13:25:56 +07:00
2 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using NLog;
using NLog.Config;
using NLog.Targets; using NLog.Targets;
using Torch.Utils; using Torch.Utils;
@@ -12,7 +14,6 @@ namespace Torch.Server
{ {
var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE") var isService = Environment.GetEnvironmentVariable("TORCH_SERVICE")
?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false; ?.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ?? false;
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
//Ensures that all the files are downloaded in the Torch directory. //Ensures that all the files are downloaded in the Torch directory.
var workingDir = AppContext.BaseDirectory; var workingDir = AppContext.BaseDirectory;
var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64"); var binDir = Path.Combine(Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? workingDir, "DedicatedServer64");
@@ -46,12 +47,24 @@ namespace Torch.Server
{ {
instancePath = Directory.CreateDirectory(instanceName).FullName; instancePath = Directory.CreateDirectory(instanceName).FullName;
} }
var oldNlog = Path.Combine(workingDir, "NLog.config");
var newNlog = Path.Combine(instancePath, "NLog.config");
if (File.Exists(oldNlog))
File.Move(oldNlog, newNlog, true);
else if (!File.Exists(newNlog))
using (var f = File.Create(newNlog))
typeof(Program).Assembly.GetManifestResourceStream("Torch.Server.NLog.config")!.CopyTo(f);
var oldTorchCfg = Path.Combine(workingDir, "Torch.cfg"); var oldTorchCfg = Path.Combine(workingDir, "Torch.cfg");
var torchCfg = Path.Combine(instancePath, "Torch.cfg"); var torchCfg = Path.Combine(instancePath, "Torch.cfg");
if (File.Exists(oldTorchCfg)) if (File.Exists(oldTorchCfg))
File.Move(oldTorchCfg, torchCfg, true); File.Move(oldTorchCfg, torchCfg, true);
Target.Register<LogViewerTarget>(nameof(LogViewerTarget));
LogManager.Configuration = new XmlLoggingConfiguration(newNlog);
LogManager.ReconfigExistingLoggers();
var config = Persistent<TorchConfig>.Load(torchCfg); var config = Persistent<TorchConfig>.Load(torchCfg);
config.Data.InstanceName = instanceName; config.Data.InstanceName = instanceName;

View File

@@ -160,6 +160,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Remove="Views\WorldSelectControl.xaml" /> <Page Remove="Views\WorldSelectControl.xaml" />
<None Include="..\NLog.config" Visible="false" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Always" /> <EmbeddedResource Include="..\NLog.config" Visible="false" />
</ItemGroup> </ItemGroup>
</Project> </Project>