Skip to content

Commit 31bd34a

Browse files
author
Michael Mantos
committed
Merge branch 'develop' into marcdemz/feature/WIN-183
2 parents 71e0f74 + 719fee5 commit 31bd34a

File tree

13 files changed

+103
-31
lines changed

13 files changed

+103
-31
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/Models/EnvironmentDetail.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ private void GetAzureInfo()
109109

110110
public static string GetDeviceName()
111111
{
112-
var deviceName = Environment.MachineName;
112+
var deviceName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
113+
if (!String.IsNullOrEmpty(deviceName))
114+
{
115+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
116+
}
117+
118+
deviceName = Environment.MachineName;
113119

114120
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
115121
{
@@ -129,7 +135,7 @@ public static string GetDeviceName()
129135
}
130136
}
131137

132-
return deviceName;
138+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
133139
}
134140

135141
public static string GetEC2InstanceId()
@@ -194,7 +200,13 @@ public static string GetEC2InstanceId()
194200
#else
195201
public static string GetDeviceName()
196202
{
197-
var deviceName = Environment.MachineName;
203+
var deviceName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
204+
if (!String.IsNullOrEmpty(deviceName))
205+
{
206+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
207+
}
208+
209+
deviceName = Environment.MachineName;
198210

199211
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
200212
{
@@ -215,7 +227,7 @@ public static string GetDeviceName()
215227
}
216228
}
217229

218-
return deviceName;
230+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
219231
}
220232

221233
public static async Task<string> GetEC2InstanceId()
@@ -233,6 +245,11 @@ public static async Task<string> GetEC2InstanceId()
233245
{
234246
string id = await content.Content.ReadAsStringAsync();
235247
r = string.IsNullOrWhiteSpace(id) ? null : id;
248+
249+
if (r.Contains("html"))
250+
{
251+
r = Environment.MachineName;
252+
}
236253
}
237254

238255
}

0 commit comments

Comments
 (0)