Skip to content

Commit ed9d11a

Browse files
Merge pull request #91 from kggayo/bug/RT-3665
Stackify-http layout renderer transferred to a new project
2 parents 3c6ee51 + cb8dd18 commit ed9d11a

File tree

7 files changed

+80
-25
lines changed

7 files changed

+80
-25
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
<ItemGroup>
2727
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
28-
<PackageReference Include="NLog" Version="4.5.0" />
29-
<PackageReference Include="NLog.Config" Version="4.5.0" />
28+
<PackageReference Include="NLog" Version="4.5.11" />
3029
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
3130
</ItemGroup>
3231

@@ -37,17 +36,5 @@
3736
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net461' ">
3837
<DefineConstants>NETFULL</DefineConstants>
3938
</PropertyGroup>
40-
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
41-
<Reference Include="System.Web" />
42-
<Reference Include="System.Web.Abstractions" />
43-
<Reference Include="System.Web.Routing" />
44-
<PackageReference Include="NLog.Web" Version="4.5.0" />
45-
</ItemGroup>
46-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
47-
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.1" />
48-
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
49-
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.1.1" />
50-
<PackageReference Include="NLog.Web.AspNetCore" Version="4.5.0" />
51-
</ItemGroup>
52-
39+
5340
</Project>

Src/NLog.Targets.Stackify/StackifyTarget.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using StackifyLib.Internal.Logs;
1010
using StackifyLib.Models;
1111
using StackifyLib.Utils;
12+
using NLog.Layouts;
1213

1314
namespace NLog.Targets.Stackify
1415
{
@@ -36,6 +37,8 @@ public class StackifyTarget : TargetWithContext
3637
[ArrayParameter(typeof(TargetPropertyWithContext), "contextproperty")]
3738
public override IList<TargetPropertyWithContext> ContextProperties { get; } = new List<TargetPropertyWithContext>();
3839

40+
public Layout StackifyHttpRequestInfo { get; set; }
41+
3942
public StackifyTarget()
4043
{
4144
Layout = "${message}${onexception:${newline}${exception:format=tostring}}";
@@ -268,16 +271,23 @@ internal LogMsg Translate(LogEventInfo loggingEvent)
268271
stackifyError = StackifyError.New(stringException);
269272
}
270273

271-
if(stackifyError.WebRequestDetail == null && contextProperties.ContainsKey("stackifyhttp"))
274+
if (StackifyHttpRequestInfo != null)
272275
{
273-
#if NETFULL
274-
string hctx = contextProperties["stackifyhttp"]?.ToString();
275-
if (!string.IsNullOrEmpty(hctx))
276+
string stackifyHttp = StackifyHttpRequestInfo.Render(loggingEvent);
277+
if (stackifyError.WebRequestDetail == null && !String.IsNullOrEmpty(stackifyHttp))
276278
{
277-
var webRequestDetail = Newtonsoft.Json.JsonConvert.DeserializeObject<WebRequestDetail>(hctx);
278-
stackifyError.WebRequestDetail = webRequestDetail;
279-
}
279+
#if NETFULL
280+
try
281+
{
282+
var webRequestDetail = Newtonsoft.Json.JsonConvert.DeserializeObject<WebRequestDetail>(stackifyHttp);
283+
stackifyError.WebRequestDetail = webRequestDetail;
284+
}
285+
catch (Exception e)
286+
{
287+
InternalLogger.Warn(e, "StackifyHttpRequestInfo: Failed to DeserializeObject");
288+
}
280289
#endif
290+
}
281291
}
282292

283293
if (stackifyError != null && !StackifyError.IgnoreError(stackifyError) && _logClient.ErrorShouldBeSent(stackifyError))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<AssemblyTitle>NLog.Web.Stackify</AssemblyTitle>
5+
<VersionPrefix>2.0.0</VersionPrefix>
6+
<TargetFrameworks>netstandard2.0;net40;net45;net461</TargetFrameworks>
7+
<AssemblyName>NLog.Web.Stackify</AssemblyName>
8+
<PackageId>NLog.Web.Stackify</PackageId>
9+
<PackageTags>stackify;errors;logs</PackageTags>
10+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
11+
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
12+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
13+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
14+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
15+
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
16+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
17+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
18+
<Version>2.1.1</Version>
19+
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
20+
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
21+
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>
22+
<RepositoryUrl>https://github.com/stackify/stackify-api-dotnet</RepositoryUrl>
23+
<RepositoryType>git</RepositoryType>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
28+
<PackageReference Include="NLog" Version="4.5.11" />
29+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
30+
</ItemGroup>
31+
32+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
33+
<DefineConstants>NETCORE</DefineConstants>
34+
</PropertyGroup>
35+
36+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net461' ">
37+
<DefineConstants>NETFULL</DefineConstants>
38+
</PropertyGroup>
39+
40+
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
41+
<Reference Include="System.Web" />
42+
<Reference Include="System.Web.Abstractions" />
43+
<Reference Include="System.Web.Routing" />
44+
<PackageReference Include="NLog.Web" Version="4.8.0" />
45+
</ItemGroup>
46+
47+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
48+
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
49+
</ItemGroup>
50+
</Project>

Src/NLog.Targets.Stackify/StackifyHttpLayoutRenderer.cs renamed to Src/NLog.Web.Stackify/StackifyHttpLayoutRenderer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
using StackifyLib.Models;
88
using Newtonsoft.Json;
99

10-
namespace NLog.Targets.Stackify
10+
namespace NLog.Web.Stackify
1111
{
1212
[LayoutRenderer("stackify-http")]
13+
[ThreadSafe]
1314
public class StackifyHttpLayoutRenderer : AspNetLayoutRendererBase
1415
{
1516
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)

Src/StackifyLibCore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{CA78
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackifyLib.UnitTests", "..\test\StackifyLib.UnitTests\StackifyLib.UnitTests.csproj", "{0A9026C3-2A91-4A45-893C-17C6AF006FA0}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.Web.Stackify", "NLog.Web.Stackify\NLog.Web.Stackify.csproj", "{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -81,6 +83,10 @@ Global
8183
{0A9026C3-2A91-4A45-893C-17C6AF006FA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
8284
{0A9026C3-2A91-4A45-893C-17C6AF006FA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
8385
{0A9026C3-2A91-4A45-893C-17C6AF006FA0}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
87+
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.Build.0 = Release|Any CPU
8490
EndGlobalSection
8591
GlobalSection(SolutionProperties) = preSolution
8692
HideSolutionNode = FALSE
@@ -96,6 +102,7 @@ Global
96102
{E141CDE4-501C-4533-8A2E-344522B1991E} = {709EEA1C-81B6-4369-AB25-6A03D4BEC75F}
97103
{28A61379-B316-480F-B45E-C622C42CAE8D} = {709EEA1C-81B6-4369-AB25-6A03D4BEC75F}
98104
{0A9026C3-2A91-4A45-893C-17C6AF006FA0} = {36B13547-8CBC-4985-9495-555500880F1D}
105+
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5} = {709EEA1C-81B6-4369-AB25-6A03D4BEC75F}
99106
EndGlobalSection
100107
GlobalSection(ExtensibilityGlobals) = postSolution
101108
SolutionGuid = {6AB55A24-BCFF-4641-90E0-7921CAD32F49}

samples/CoreConsoleApp/CoreConsoleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
2323
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
2424
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
25-
<PackageReference Include="NLog" Version="4.5.0" />
25+
<PackageReference Include="NLog" Version="4.5.11" />
2626
<PackageReference Include="Serilog" Version="2.4.0" />
2727
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
2828
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />

samples/CoreWebApp/CoreWebApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.2" />
3232
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
3333
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
34-
<PackageReference Include="NLog" Version="4.5.0" />
34+
<PackageReference Include="NLog" Version="4.5.11" />
3535
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0-rtm-rc4" />
3636
<PackageReference Include="Serilog" Version="2.4.0" />
3737
<PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />

0 commit comments

Comments
 (0)