forked from MarcelRaschke/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
33 lines (28 loc) · 1.13 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
using PostSharp.Patterns.Diagnostics;
using PostSharp.Patterns.Diagnostics.Backends.Serilog;
using PostSharp.Samples.Logging.BusinessLogic;
using Serilog;
// Add logging to all methods of this project.
[assembly: Log]
namespace PostSharp.Samples.Logging.Serilog
{
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
internal class Program
{
private static void Main(string[] args)
{
// The output template must include {Indent} for nice output.
const string template = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Indent:l}{Message}{NewLine}{Exception}";
// Configure a Serilog logger.
var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File("serilog.log", outputTemplate: template)
.WriteTo.ColoredConsole(outputTemplate: template)
.CreateLogger();
// Configure PostSharp Logging to use Serilog
LoggingServices.DefaultBackend = new SerilogLoggingBackend(logger);
// Simulate some business logic.
QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
}
}
}