forked from 47-studio-org/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
49 lines (37 loc) · 1.36 KB
/
Program.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
using NLog;
using NLog.Config;
using NLog.Targets;
using PostSharp.Patterns.Diagnostics;
using PostSharp.Patterns.Diagnostics.Backends.NLog;
using PostSharp.Samples.Logging.BusinessLogic;
using LogLevel = NLog.LogLevel;
// Add logging to all methods of this project.
[assembly: Log]
namespace PostSharp.Samples.Logging.NLog
{
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
internal static class Program
{
private static void Main(string[] args)
{
// Configure NLog.
var nlogConfig = new LoggingConfiguration();
var fileTarget = new FileTarget("file")
{
FileName = "nlog.log",
KeepFileOpen = true,
ConcurrentWrites = false
};
nlogConfig.AddTarget(fileTarget);
nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));
var consoleTarget = new ConsoleTarget("console");
nlogConfig.AddTarget(consoleTarget);
nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));
// Configure PostSharp Logging to use NLog.
LoggingServices.DefaultBackend = new NLogLoggingBackend(new LogFactory(nlogConfig));
LogManager.EnableLogging();
// Simulate some business logic.
QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
}
}
}