Skip to content

Commit c5146e5

Browse files
committed
Updated README.md about structured logging in NLog 4.5
1 parent 9a4ef7c commit c5146e5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Library for Stackify users to integrate Stackify in to their projects. Provides
1919
**Read me sections:**
2020
- [Basics](#basics)
2121
- [Errors & Logs](#errors-and-logs)
22-
- [StackifyLib NLog](#nlog-2012---v31)
22+
- [StackifyLib NLog](#nlog)
2323
- [StackifyLib log4net 2.0+](#log4net-v20-v1211)
2424
- [StackifyLib log4net 1.2.10](#log4net-v1210)
2525
- [Direct API](#direct-api)
@@ -94,7 +94,7 @@ static void StackifyAPILogger_OnLogMessage(string data)
9494
If you log an object with the message, Stackify's log viewer makes it easy to search by these parameters. You can always search by the text in the log message itself, but searching by the logged properties provides a lot more power. If you always logged a "clientid" for example on every log message, you could search in Stackify for "json.clientid:1" and quickly see all logs and errors affecting that specific client. Another big difference and advantage to logging objects is you can do a range type search "json.clientid:[1 TO 10]" which would not be possible by a straight text search.
9595

9696

97-
### NLog 4.5
97+
### NLog
9898

9999
**Install via NuGet package**
100100
```
@@ -119,14 +119,24 @@ Sample config:
119119
</nlog>
120120
```
121121

122-
Logging custom objects is supported and will be searchable in Stackify's log viewer
122+
123+
NLog 4.5 (and newer) supports message templates, where structured properties becomes searchable in Stackify's log viewer
124+
125+
```csharp
126+
static NLog.Logger nlog = NLog.LogManager.GetCurrentClassLogger();
127+
nLog.Debug("{clientid} chose {color}", 1, "red");
128+
```
129+
130+
Logging custom objects are also supported and will be searchable in Stackify's log viewer
123131

124132
```csharp
125133
static NLog.Logger nlog = NLog.LogManager.GetCurrentClassLogger();
126134
Dictionary<string, object> dictionary = new Dictionary<string, object>();
127135
dictionary["clientid"] = 1;
128136
dictionary["color"] = "red";
129137
nlog.Debug("Test message", dictionary);
138+
139+
nlog.Debug("Test message", new { clientid = 2, color = "blue" });
130140
```
131141

132142
Options:

0 commit comments

Comments
 (0)