Skip to content

Commit eb649cc

Browse files
authored
Merge pull request #1 from homiedopie/marcdemz/feature/WIN-183
Marcdemz/feature/win 183 - Update test
2 parents 71e0f74 + 6da60a0 commit eb649cc

File tree

22 files changed

+289
-39
lines changed

22 files changed

+289
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ packages/
2929

3030
**/bin/*
3131
**/obj/*
32+
BuildOutput/
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ Library for Stackify users to integrate Stackify in to their projects. Provides
99
- [Stackify homepage](http://www.stackify.com)
1010
- [Stackify documentation site](https://docs.stackify.com/docs)
1111
- [NuGet packages](https://www.nuget.org/packages?q=Stackify)
12-
- [Configure log4net](https://docs.stackify.com/docs/errors-and-logs-log4net)
12+
- [Supported .NET logging frameworks](https://docs.stackify.com/docs/errors-and-logs-net-supported-frameworks)
1313
- [Best practices for logging with C#](https://stackify.com/csharp-logging-best-practices/)
1414
- [Why you should use tags in your logs](https://stackify.com/get-smarter-log-management-with-log-tags/)
1515
- [Ultimate log4net Tutorial for .Net Logging](https://stackify.com/log4net-guide-dotnet-logging/)
1616

1717

18-
1918
**Read me sections:**
2019
- [Basics](#basics)
2120
- [Errors & Logs](#errors-and-logs)
22-
- [StackifyLib NLog](#nlog-2012---v31)
21+
- [StackifyLib NLog](#nlog)
2322
- [StackifyLib log4net 2.0+](#log4net-v20-v1211)
2423
- [StackifyLib log4net 1.2.10](#log4net-v1210)
2524
- [Direct API](#direct-api)
@@ -94,42 +93,52 @@ static void StackifyAPILogger_OnLogMessage(string data)
9493
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.
9594

9695

97-
### NLog 4.5
96+
### NLog
9897

9998
**Install via NuGet package**
10099
```
101100
PM> Install-Package NLog.Targets.Stackify
102101
```
103102

104-
Sample config:
103+
**Sample config:**
105104
```xml
106105
<nlog>
107106
<extensions>
108107
<add assembly="NLog.Targets.Stackify"/>
109108
</extensions>
110109
<targets>
111-
<target name="stackify" type="StackifyTarget" logAllParams="false">
112-
<contextproperty name="gdcKey1" layout="${gdc:item=gdcKey1}" />
113-
<contextproperty name="mdlcKey2" layout="${mdlc:item=mdlcKey2}" />
114-
</target>
110+
<target name="stackify" type="StackifyTarget" logAllParams="false">
111+
<contextproperty name="gdcKey1" layout="${gdc:item=gdcKey1}" />
112+
<contextproperty name="mdlcKey2" layout="${mdlc:item=mdlcKey2}" />
113+
</target>
115114
</targets>
116115
<rules>
117116
<logger name="*" writeTo="stackify" minlevel="Debug" />
118117
</rules>
119118
</nlog>
120119
```
121120

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

124131
```csharp
125132
static NLog.Logger nlog = NLog.LogManager.GetCurrentClassLogger();
126133
Dictionary<string, object> dictionary = new Dictionary<string, object>();
127134
dictionary["clientid"] = 1;
128135
dictionary["color"] = "red";
129136
nlog.Debug("Test message", dictionary);
137+
138+
nlog.Debug("Test message", new { clientid = 2, color = "blue" });
130139
```
131140

132-
Options:
141+
**Options:**
133142

134143
- IncludeEventProperties - Include LogEvent-Properties for structured logging.
135144
- IncludeMdlc - Include NLog MappedDiagnosticsLogicalContext MDLC-Properties for structured logging.
@@ -156,7 +165,7 @@ Note: Nuget packages are compiled against 2.0.0 (1.2.11) but any newer version w
156165
</dependentAssembly>
157166
```
158167

159-
Sample config:
168+
**Sample config:**
160169
```xml
161170
<log4net>
162171
<root>
@@ -183,7 +192,7 @@ Sample config:
183192
</log4net>
184193
```
185194

186-
Options
195+
**Options:**
187196

188197
- GlobalContext, ThreadContext, and LogicalThreadContext keys are fully supported by setting the parameters in the config as a comma delimited list of keys. See sample config above.
189198
- CallContextKeys is an additional feature unrelated to log4net that uses the local thread storage for more advanced tracking of context variables. LogicalThreadContext provides the same functionality but uses an internal property collection. We have seen instances where the serialization of that collection can cause exceptions. This was created as an alternative method to the built in function. 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.
@@ -194,7 +203,7 @@ Options
194203

195204
log4net does not internally have methods for logging a log message along with an object. Stackify's appenders work fine if you log an object directly or we have created some friendly extension methods to make it easy to log an object with your message at the same time.
196205

197-
```cshapr
206+
```csharp
198207
using StackifyLib; //extension methods are here
199208
static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Program));
200209
Dictionary<string, object> dictionary = new Dictionary<string, object>();

Src/FFWebApp462/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Antlr" version="3.5.0.2" targetFramework="net462" />
4-
<package id="bootstrap" version="3.3.7" targetFramework="net462" />
4+
<package id="bootstrap" version="3.4.1" targetFramework="net462" />
55
<package id="jQuery" version="3.3.1" targetFramework="net462" />
66
<package id="log4net" version="2.0.8" targetFramework="net462" />
77
<package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net462" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
1616
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
1717
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
18-
<Version>2.1.6</Version>
18+
<Version>2.1.7</Version>
1919
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
2020
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
2121
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>

Src/StackifyLib.AspNetCore/StackifyLib.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1111
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1212
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
13-
<Version>2.1.5</Version>
13+
<Version>2.1.6</Version>
1414
<Description>StackifyLib.AspNetCore</Description>
1515
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
1616
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>

Src/StackifyLib.log4net/StackifyAppender.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Threading;
45
using StackifyLib.Internal.Logs;
56
using StackifyLib.Models;
67
using StackifyLib.Utils;
@@ -321,7 +322,7 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
321322
}
322323
}
323324
}
324-
#if NETFULL
325+
325326
foreach (string mdcKey in _LogicalThreadContextKeys)
326327
{
327328
object mdcValue = Apache_log4net.LogicalThreadContext.Properties[mdcKey];
@@ -355,8 +356,8 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
355356
properties[mdcKey.ToLower()] = mdcValue;
356357
}
357358
}
358-
359359

360+
#if NETFULL
360361
foreach (string key in _CallContextKeys)
361362
{
362363
object value = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData(key);
@@ -366,7 +367,6 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
366367
properties[key.ToLower()] = value;
367368
}
368369
}
369-
370370
#endif
371371

372372
return properties;

Src/StackifyLib.log4net/StackifyLib.log4net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1414
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1515
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
16-
<Version>2.1.0</Version>
16+
<Version>2.1.5</Version>
1717
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
1818
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
1919
<RepositoryUrl>https://github.com/stackify/stackify-api-dotnet</RepositoryUrl>

Src/StackifyLib/Config.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ public static void ReadStackifyJSONConfig(string filePath)
228228

229229
public static void SetStackifyObj(JObject obj)
230230
{
231-
AppName = TryGetValue(obj, "AppName");
232-
Environment = TryGetValue(obj, "Environment");
233-
ApiKey = TryGetValue(obj, "ApiKey");
231+
AppName = TryGetValue(obj, "AppName") ?? AppName;
232+
Environment = TryGetValue(obj, "Environment") ?? Environment;
233+
ApiKey = TryGetValue(obj, "ApiKey") ?? ApiKey;
234234
}
235235

236236
private static string TryGetValue(JToken jToken, string key)
@@ -240,14 +240,23 @@ private static string TryGetValue(JToken jToken, string key)
240240
try
241241
{
242242
var val = jToken[key];
243-
if (val != null)
243+
if (val == null)
244244
{
245-
r = val.ToString();
245+
StackifyAPILogger.Log($"#Config #TryGetValue #Json failed - Property is null or empty - Property: {key}");
246+
return r;
246247
}
248+
249+
if (val.Type != JTokenType.String || (val.Type == JTokenType.String && string.IsNullOrEmpty(val.ToString())))
250+
{
251+
StackifyAPILogger.Log($"#Config #TryGetValue #Json failed - Property is not a string - Property: {key}");
252+
return r;
253+
}
254+
255+
r = val.ToString();
247256
}
248257
catch (Exception ex)
249258
{
250-
StackifyAPILogger.Log("#Config #TryGetValue failed", ex);
259+
StackifyAPILogger.Log("#Config #TryGetValue #Json failed", ex);
251260
}
252261

253262
return r;

0 commit comments

Comments
 (0)