-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
30 lines (25 loc) · 906 Bytes
/
Program.cs
File metadata and controls
30 lines (25 loc) · 906 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NLogCustomLoggingContext
{
class Program
{
static NLog.Logger logger;
static void Main(string[] args)
{
logger = NLog.LogManager.GetCurrentClassLogger();
//Set the MDLC context for trackingId (ideally you'd use this in an Async/Await context and set this as early as possible)
//In reality Global Diagnostics Context (GDC) would be preferable in a serial non-async app such as this example
NLog.MappedDiagnosticsLogicalContext.Set("trackingId", Guid.NewGuid());
DoWork("log it");
DoWork("log it again"); //Should get same trackingId
}
static void DoWork(string theWork)
{
logger.Debug("Doing work: {0}", theWork);
}
}
}