Skip to content

Commit 7f720a1

Browse files
committed
Implement user nlog configs, update updater to ignore user config. Resolves #309
Also changes FilesystemManager to use system temp directory when appropriate. (reduces clutter on disk)
1 parent 93bb11c commit 7f720a1

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎NLog-user.config‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" />
5+
<variable name="logContent" value="${message:withException=true}"/>
6+
7+
<targets async="true">
8+
<target xsi:type="Null" name="null" formatMessage="false" />
9+
<target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
10+
<target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" />
11+
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
12+
<target xsi:type="ColoredConsole" name="console" layout="${var:logStamp} ${logger:shortName=true}: ${var:logContent}" />
13+
<target xsi:type="File" name="patch" layout="${var:logContent}" fileName="Logs\patch.log"/>
14+
<target xsi:type="FlowDocument" name="wpf" layout="${var:logStamp} ${logger:shortName=true}: ${var:logContent}" />
15+
</targets>
16+
17+
<rules>
18+
<!-- Define custom rules below. The example line will pipe all debug output to log file, in-UI console, and independent console. -->
19+
<!--<logger name="*" minlevel="Debug" writeTo="main, console, wpf" />-->
20+
</rules>
21+
</nlog>

‎NLog.config‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" />
55
<variable name="logContent" value="${message:withException=true}"/>
66

7+
<include file="NLog-user.config"/>
8+
79
<targets async="true">
810
<target xsi:type="Null" name="null" formatMessage="false" />
911
<target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
@@ -15,6 +17,7 @@
1517
</targets>
1618

1719
<rules>
20+
<!-- Do not define custom rules here. Use NLog-user.config -->
1821
<logger name="Keen" minlevel="Warn" writeTo="main"/>
1922
<logger name="Keen" minlevel="Info" writeTo="console, wpf"/>
2023
<logger name="Keen" minlevel="Debug" writeTo="keen" final="true" />

‎Torch/Managers/FilesystemManager.cs‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using NLog;
78
using Torch.API;
89

910
namespace Torch.Managers
1011
{
1112
public class FilesystemManager : Manager
1213
{
14+
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
1315
/// <summary>
1416
/// Temporary directory for Torch that is cleared every time the program is started.
1517
/// </summary>
@@ -22,11 +24,20 @@ public class FilesystemManager : Manager
2224

2325
public FilesystemManager(ITorchBase torchInstance) : base(torchInstance)
2426
{
27+
var tmp = Path.Combine(Path.GetTempPath(), "Torch");
2528
var torch = new FileInfo(typeof(FilesystemManager).Assembly.Location).Directory.FullName;
26-
TempDirectory = Directory.CreateDirectory(Path.Combine(torch, "tmp")).FullName;
27-
TorchDirectory = torch;
29+
if (Path.GetPathRoot(tmp) == Path.GetPathRoot(torch))
30+
{
31+
TempDirectory = tmp;
32+
}
33+
else
34+
{
35+
TempDirectory = Directory.CreateDirectory(Path.Combine(torch, "tmp")).FullName;
36+
TorchDirectory = torch;
2837

29-
ClearTemp();
38+
_log.Info($"Clearing tmp directory at {TempDirectory}");
39+
ClearTemp();
40+
}
3041
}
3142

3243
private void ClearTemp()

‎Torch/Managers/UpdateManager.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ private async void CheckAndUpdateTorch()
5555
_log.Info("Failed to fetch latest version.");
5656
return;
5757
}
58-
59-
_log.Info($"Clearing tmp directory at {_fsManager.TempDirectory}");
6058

6159
if (job.Version > Torch.TorchVersion)
6260
{
@@ -90,6 +88,9 @@ private void UpdateFromZip(string zipFile, string extractPath)
9088
{
9189
foreach (var file in zip.Entries)
9290
{
91+
if(file.Name == "NLog-user.config" && File.Exists(Path.Combine(extractPath, file.FullName)))
92+
continue;
93+
9394
_log.Debug($"Unzipping {file.FullName}");
9495
var targetFile = Path.Combine(extractPath, file.FullName);
9596
_fsManager.SoftDelete(extractPath, file.FullName);

0 commit comments

Comments
 (0)