-
Notifications
You must be signed in to change notification settings - Fork 9
/
FNLog.cs
executable file
·69 lines (59 loc) · 2.56 KB
/
FNLog.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using FreenetTray.Properties;
using NLog;
using NLog.Config;
using NLog.Targets;
using System;
namespace FreenetTray {
class FNLog {
/* This class allows logging to reach the VS console during development,
* regardless of how NLog is configured.
*
* It appears that NLog is supposed to allow logging to the VS console,
* but it frequently does not work correctly. Note that this also
* prevents NLog from knowing which class originally printed a log
* statement, but for our purposes that shouldn't affect anything as
* we log full exceptions when necessary anyway.
*
*/
public const string LogTargetName = "logFile";
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public static void Initialize() {
var config = new LoggingConfiguration();
var target = new FileTarget {FileName = "${basedir}/FreenetTray.log"};
config.AddTarget(LogTargetName, target);
var rule = new LoggingRule("*", LogLevel.FromString(Settings.Default.LogLevel), target);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
}
public static void Debug(string format, params object[] args) {
string f = "[Debug] " + format;
string line = string.Format(f, args);
System.Diagnostics.Debug.WriteLine(line);
Log.Info(format, args);
}
public static void Info(string format, params object[] args) {
string f = "[Info] " + format;
string line = string.Format(f, args);
System.Diagnostics.Debug.WriteLine(line);
Log.Info(format, args);
}
public static void Warn(string format, params object[] args) {
string f = "[Warn] " + format;
string line = string.Format(f, args);
System.Diagnostics.Debug.WriteLine(line);
Log.Warn(format, args);
}
public static void Error(string format, params object[] args) {
string f = "[Error] " + format;
string line = string.Format(f, args);
System.Diagnostics.Debug.WriteLine(line);
Log.Error(format, args);
}
public static void ErrorException(Exception ex, string format, params object[] args) {
string f = "[Error] " + format;
string line = string.Format(f, args);
System.Diagnostics.Debug.WriteLine(line);
Log.Log(LogLevel.Error, ex, format, args);
}
}
}