Skip to content

Commit 7049879

Browse files
Merge pull request #83 from snakefoot/master
NLog StackifyTarget with support for MappedDiagnosticsLogicalContext
2 parents d601def + 2791661 commit 7049879

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
@@ -80,7 +80,7 @@ If you are having problems you can get logging out of the framework by hooking i
8080
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.
8181

8282

83-
### NLog 2.0.1.2 - v3.1+
83+
### NLog 4.5
8484

8585
**Install via NuGet package**
8686
```
@@ -94,8 +94,10 @@ Sample config:
9494
<add assembly="NLog.Targets.Stackify"/>
9595
</extensions>
9696
<targets>
97-
<target name="stackify" type="StackifyTarget" globalContextKeys="examplekey1,key2"
98-
mappedContextKeys="" callContextKeys="" logMethodNames="true" />
97+
<target name="stackify" type="StackifyTarget" logAllParams="false">
98+
<contextproperty name="gdcKey1" layout="${gdc:item=gdcKey1}" />
99+
<contextproperty name="mdlcKey2" layout="${mdlc:item=mdlcKey2}" />
100+
</target>
99101
</targets>
100102
<rules>
101103
<logger name="*" writeTo="stackify" minlevel="Debug" />
@@ -110,11 +112,16 @@ Logging custom objects is supported and will be searchable in Stackify's log vie
110112
dictionary["color"] = "red";
111113
nlog.Debug("Test message", dictionary);
112114

113-
Options
115+
Options:
114116

115-
- 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.
116-
- 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.
117-
- 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.
117+
- IncludeEventProperties - Include LogEvent-Properties for structured logging.
118+
- IncludeMdlc - Include NLog MappedDiagnosticsLogicalContext MDLC-Properties for structured logging.
119+
- IncludeCallSite - Include LogEvent CallSite so method names will show up in the StackifyLog viewer (Replaces old property logMethodNames)
120+
- logLastParameter - Serialize the last parameter provided with the LogEvent.
121+
- logAllParams - Serialize all the parameters provided with the LogEvent (arg0, arg1, etc.)
122+
- GlobalContextKeys - Comma delimited list of keys for NLog GDC. !OBSOLETE! Instead use contextproperty-Layout as shown in sample config above.
123+
- MappedContextKeys - Comma delimited list of keys for NLog MDC. !OBSOLETE! Instead use contextproperty-Layout as shown in sample config above.
124+
- 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.
118125

119126
### log4net v2.0+ (v1.2.11+)
120127

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)