Skip to content

Commit 2791661

Browse files
committed
NLog StackifyTarget with support for MappedDiagnosticsLogicalContext - MDLC
1 parent 06005c2 commit 2791661

File tree

5 files changed

+130
-183
lines changed

5 files changed

+130
-183
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ If you are having problems you can get logging out of the framework by hooking i
7777
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.
7878

7979

80-
### NLog 2.0.1.2 - v3.1+
80+
### NLog 4.5
8181

8282
**Install via NuGet package**
8383
```
@@ -91,8 +91,10 @@ Sample config:
9191
<add assembly="NLog.Targets.Stackify"/>
9292
</extensions>
9393
<targets>
94-
<target name="stackify" type="StackifyTarget" globalContextKeys="examplekey1,key2"
95-
mappedContextKeys="" callContextKeys="" logMethodNames="true" />
94+
<target name="stackify" type="StackifyTarget" logAllParams="false">
95+
<contextproperty name="gdcKey1" layout="${gdc:item=gdcKey1}" />
96+
<contextproperty name="mdlcKey2" layout="${mdlc:item=mdlcKey2}" />
97+
</target>
9698
</targets>
9799
<rules>
98100
<logger name="*" writeTo="stackify" minlevel="Debug" />
@@ -107,11 +109,16 @@ Logging custom objects is supported and will be searchable in Stackify's log vie
107109
dictionary["color"] = "red";
108110
nlog.Debug("Test message", dictionary);
109111

110-
Options
112+
Options:
111113

112-
- GlobalContext and MappedContext keys are fully supported by setting the parameters in the config as a comma delimited list of keys. See sample config above.
113-
- CallContextKeys is an additional feature unrelated to NLog that uses the local thread storage for more advanced tracking of context variables. It is used via CallContext.LogicalSetData(key, value). Research LogicalSetData online to learn more. It is supposed to work better across child Task objects and with async.
114-
- logMethodNames - Method names will show up in the StackifyLog viewer most of the time as the class name that did the logging. For exceptions it will usually show the method name. To enable the exact method name for all logging, set this property to true. Note that it does cause a small performance hit due to walking the StackTrace.
114+
- IncludeEventProperties - Include LogEvent-Properties for structured logging.
115+
- IncludeMdlc - Include NLog MappedDiagnosticsLogicalContext MDLC-Properties for structured logging.
116+
- IncludeCallSite - Include LogEvent CallSite so method names will show up in the StackifyLog viewer (Replaces old property logMethodNames)
117+
- logLastParameter - Serialize the last parameter provided with the LogEvent.
118+
- logAllParams - Serialize all the parameters provided with the LogEvent (arg0, arg1, etc.)
119+
- GlobalContextKeys - Comma delimited list of keys for NLog GDC. !OBSOLETE! Instead use contextproperty-Layout as shown in sample config above.
120+
- MappedContextKeys - Comma delimited list of keys for NLog MDC. !OBSOLETE! Instead use contextproperty-Layout as shown in sample config above.
121+
- CallContextKeys - Comma delimited list of keys for use with CallContext.LogicalSetData(key, value). Research LogicalSetData online to learn more. !OBSOLETE! Instead use contextproperty-Layout as shown in sample config above.
115122

116123
### log4net v2.0+ (v1.2.11+)
117124

Src/NLog.Targets.Stackify/NLog.Targets.Stackify.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<AssemblyTitle>NLog.Targets.Stackify</AssemblyTitle>
55
<VersionPrefix>2.0.0</VersionPrefix>
6-
<TargetFrameworks>netstandard2.0;net40;net45;net451;net452;net46</TargetFrameworks>
6+
<TargetFrameworks>netstandard2.0;net40;net45;net461</TargetFrameworks>
77
<AssemblyName>NLog.Targets.Stackify</AssemblyName>
88
<PackageId>NLog.Targets.Stackify</PackageId>
99
<PackageTags>stackify;errors;logs</PackageTags>
@@ -25,18 +25,14 @@
2525

2626
<ItemGroup>
2727
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
28+
<PackageReference Include="NLog" Version="4.5.0" />
2829
</ItemGroup>
2930

3031
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3132
<DefineConstants>NETCORE</DefineConstants>
3233
</PropertyGroup>
3334

34-
<ItemGroup>
35-
<PackageReference Include="NLog" Version="4.5.0" />
36-
<Reference Include="Microsoft.CSharp" />
37-
</ItemGroup>
38-
39-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' OR '$(TargetFramework)' == 'net452' OR '$(TargetFramework)' == 'net46' ">
35+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net461' ">
4036
<DefineConstants>NETFULL</DefineConstants>
4137
</PropertyGroup>
4238

0 commit comments

Comments
 (0)