-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathNlogManager.cs
48 lines (43 loc) · 1.85 KB
/
NlogManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Text;
using NLog;
using NLog.Config;
using NLog.Targets;
namespace PatreonDownloader.App
{
internal static class NLogManager
{
public static void ReconfigureNLog(Enums.LogLevel logLevel = Enums.LogLevel.Default, bool saveLogs = false)
{
LoggingConfiguration configuration = new LoggingConfiguration();
ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget("console")
{
Layout = "${longdate} ${uppercase:${level}} ${message}"
};
configuration.AddTarget(consoleTarget);
FileTarget fileTarget = new FileTarget("file")
{
FileName = "${basedir}/logs/${shortdate}.log",
Layout = "${longdate} ${uppercase:${level}} [${logger}] ${message}"
};
configuration.AddTarget(fileTarget);
LogLevel nlogLogLevel = LogLevel.Info;
switch (logLevel)
{
case Enums.LogLevel.Debug:
nlogLogLevel = LogLevel.Debug;
break;
case Enums.LogLevel.Trace:
nlogLogLevel = LogLevel.Trace;
break;
}
configuration.AddRule(nlogLogLevel, LogLevel.Fatal, consoleTarget, nlogLogLevel != LogLevel.Info ? "*" : "PatreonDownloader.App.*");
if(saveLogs)
configuration.AddRule(nlogLogLevel, LogLevel.Fatal, fileTarget, nlogLogLevel != LogLevel.Info ? "*" : "PatreonDownloader.App.*");
//configuration.AddRule(debug ? LogLevel.Debug : LogLevel.Info, LogLevel.Fatal, consoleTarget, debug ? "*" : "PatreonDownloader.PuppeteerEngine.*");
//configuration.AddRuleForAllLevels(fileTarget);
LogManager.Configuration = configuration;
}
}
}