Skip to content

Commit f5eaa3c

Browse files
committed
Add microsoft.configuration.extensions compat for net461+
1 parent 2693eb1 commit f5eaa3c

14 files changed

+181
-243
lines changed

Diff for: Src/CoreConsoleApp/CoreConsoleApp.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
55
<AssemblyName>CoreConsoleApp</AssemblyName>
66
<OutputType>Exe</OutputType>
77
<PackageId>CoreConsoleApp</PackageId>
@@ -27,11 +27,11 @@
2727
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
2828
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
2929
</ItemGroup>
30-
30+
3131
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3232
<DefineConstants>NETCORE</DefineConstants>
3333
</PropertyGroup>
34-
34+
3535
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' OR '$(TargetFramework)' == 'net452' OR '$(TargetFramework)' == 'net46' ">
3636
<DefineConstants>NETFULL</DefineConstants>
3737
</PropertyGroup>

Diff for: Src/CoreConsoleApp/Program.cs

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace CoreConsoleApp
1717
{
1818
public class Program
1919
{
20-
21-
22-
2320
static void Main(string[] args)
2421
{
2522
var builder = new ConfigurationBuilder()

Diff for: Src/StackifyLib.AspNetCore/Configure.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using StackifyLib.Models;
63

74
namespace StackifyLib.AspNetCore
85
{
96
internal class Configure
107
{
11-
128
internal static IServiceProvider ServiceProvider { get; set; }
139

1410
internal static void SubscribeToWebRequestDetails(IServiceProvider serviceProvider)
1511
{
1612
if (ServiceProvider != null)
13+
{
1714
return;
15+
}
1816

1917
ServiceProvider = serviceProvider;
2018

2119
WebRequestDetail.SetWebRequestDetail += WebRequestDetailMapper.WebRequestDetail_SetWebRequestDetail;
2220
}
2321
}
24-
25-
}
22+
}

Diff for: Src/StackifyLib.AspNetCore/Extensions.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Threading.Tasks;
63
using StackifyLib.AspNetCore;
74

85
namespace StackifyLib
96
{
107
public static class Extensions
118
{
12-
13-
14-
15-
public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IApplicationBuilder app,
16-
Microsoft.Extensions.Configuration.IConfigurationRoot configuration)
9+
public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.Extensions.Configuration.IConfigurationRoot configuration)
1710
{
1811
try
1912
{
@@ -29,8 +22,8 @@ public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IA
2922
}
3023
catch (Exception ex)
3124
{
32-
Debug.WriteLine("Error in AddStackifyLogging " + ex.ToString());
25+
Debug.WriteLine($"Error in ConfigureStackifyLogging {ex}");
3326
}
3427
}
3528
}
36-
}
29+
}

Diff for: Src/StackifyLib.AspNetCore/StackifyLib.AspNetCore.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>StackifyLib for AspNetCore</AssemblyTitle>
5-
<VersionPrefix>2.0.0</VersionPrefix>
6-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<VersionPrefix>2.1.0</VersionPrefix>
6+
<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
77
<AssemblyName>StackifyLib.AspNetCore</AssemblyName>
88
<PackageId>StackifyLib.AspNetCore</PackageId>
99
<PackageTags>stackify;metrics;errors;logs</PackageTags>
1010
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1111
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1212
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
13-
<Version>2.1.0</Version>
13+
<Version>2.1.1</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>

Diff for: Src/StackifyLib.AspNetCore/WebRequestDetailMapper.cs

+30-88
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using StackifyLib.Models;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Linq;
5-
using System.Threading.Tasks;
64
using Microsoft.AspNetCore.Http;
75
using Microsoft.AspNetCore.Routing;
8-
using Microsoft.Extensions.Primitives;
96
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Primitives;
8+
using StackifyLib.Models;
109

1110
namespace StackifyLib.AspNetCore
1211
{
@@ -22,67 +21,43 @@ internal static void WebRequestDetail_SetWebRequestDetail(WebRequestDetail detai
2221
var context = Configure.ServiceProvider?.GetService<IHttpContextAccessor>()?.HttpContext;
2322

2423
if (context == null)
24+
{
2525
return;
26+
}
2627

2728
Load(context, detail);
2829
}
2930

3031
private static void Load(HttpContext context, WebRequestDetail detail)
3132
{
3233
if (context == null || context.Request == null)
34+
{
3335
return;
36+
}
3437

35-
HttpRequest request = context.Request;
38+
var request = context.Request;
3639

3740
try
3841
{
3942
detail.HttpMethod = request.Method;
40-
41-
detail.UserIPAddress = context?.Connection?.RemoteIpAddress?.ToString();
42-
43-
44-
//if (context.Items != null && context.Items.Contains("Stackify.ReportingUrl"))
45-
//{
46-
// ReportingUrl = context.Items["Stackify.ReportingUrl"].ToString();
47-
//}
48-
49-
50-
if (request.IsHttps)
51-
{
52-
detail.RequestProtocol = "https";
53-
}
54-
else
55-
{
56-
detail.RequestProtocol = "http";
57-
}
58-
detail.RequestUrl = detail.RequestProtocol + "//" + request.Host + request.Path;
59-
60-
43+
detail.UserIPAddress = context.Connection?.RemoteIpAddress?.ToString();
44+
detail.RequestProtocol = request.IsHttps ? "https" : "http";
45+
detail.RequestUrl = $"{detail.RequestProtocol}//{request.Host}{request.Path}";
6146
detail.MVCAction = context.GetRouteValue("action")?.ToString();
6247
detail.MVCController = context.GetRouteValue("controller")?.ToString();
6348

64-
if (!string.IsNullOrEmpty(detail.MVCAction) && !string.IsNullOrEmpty(detail.MVCController))
49+
if (string.IsNullOrEmpty(detail.MVCAction) == false && string.IsNullOrEmpty(detail.MVCController) == false)
6550
{
66-
detail.ReportingUrl = detail.MVCController + "." + detail.MVCAction;
51+
detail.ReportingUrl = $"{detail.MVCController}.{detail.MVCAction}";
6752
}
68-
69-
70-
//if (request.AppRelativeCurrentExecutionFilePath != null)
71-
//{
72-
// RequestUrlRoot = request.AppRelativeCurrentExecutionFilePath.TrimStart('~');
73-
//}
74-
7553
}
7654
catch (Exception)
7755
{
78-
56+
// ignored
7957
}
8058

81-
82-
8359
try
8460
{
85-
8661
if (request.QueryString != null)
8762
{
8863
detail.QueryString = ToKeyValues(request.Query, null, null);
@@ -95,12 +70,12 @@ private static void Load(HttpContext context, WebRequestDetail detail)
9570
Config.ErrorHeaderBadKeys = new List<string>();
9671
}
9772

98-
if (!Config.ErrorHeaderBadKeys.Contains("cookie"))
73+
if (Config.ErrorHeaderBadKeys.Contains("cookie") == false)
9974
{
10075
Config.ErrorHeaderBadKeys.Add("cookie");
10176
}
10277

103-
if (!Config.ErrorHeaderBadKeys.Contains("authorization"))
78+
if (Config.ErrorHeaderBadKeys.Contains("authorization") == false)
10479
{
10580
Config.ErrorHeaderBadKeys.Add("authorization");
10681
}
@@ -117,66 +92,33 @@ private static void Load(HttpContext context, WebRequestDetail detail)
11792
{
11893
detail.PostData = ToKeyValues(request.Form, null, null);
11994
}
120-
121-
//sessions return a byte array...
122-
//if (context.Session != null && Config.CaptureSessionVariables && Config.ErrorSessionGoodKeys.Any())
123-
//{
124-
// SessionData = new Dictionary<string, string>();
125-
126-
// foreach (var key in Config.ErrorSessionGoodKeys)
127-
// {
128-
// SessionData[key] = context.Session
129-
// }
130-
131-
132-
//}
133-
134-
//if (Config.CaptureErrorPostdata)
135-
//{
136-
// var contentType = context.Request.Headers["Content-Type"];
137-
138-
// if (contentType != "text/html" && contentType != "application/x-www-form-urlencoded" &&
139-
// context.Request.RequestType != "GET")
140-
// {
141-
// int length = 4096;
142-
// string postBody = new StreamReader(context.Request.InputStream).ReadToEnd();
143-
// if (postBody.Length < length)
144-
// {
145-
// length = postBody.Length;
146-
// }
147-
148-
// PostDataRaw = postBody.Substring(0, length);
149-
// }
150-
//}
15195
}
15296
catch (Exception)
15397
{
98+
// ignored
15499
}
155100
}
156101

157-
//IEnumerable<KeyValuePair<string, StringValues>>
158-
//IEnumerable<KeyValuePair<string, string>>
159102
internal static Dictionary<string, string> ToKeyValues(IEnumerable<KeyValuePair<string, StringValues>> collection, List<string> goodKeys, List<string> badKeys)
160103
{
161-
//var keys = collection.Keys;
162104
var items = new Dictionary<string, string>();
163105

164-
foreach (var item in collection)
106+
foreach (KeyValuePair<string, StringValues> item in collection)
165107
{
166-
string key = item.Key;
108+
var key = item.Key;
109+
167110
try
168111
{
169112
object val = item.Value.ToString();
170113

171-
if (val != null && !string.IsNullOrWhiteSpace(val.ToString()) && items.ContainsKey(key))
114+
if (val != null && string.IsNullOrWhiteSpace(val.ToString()) == false && items.ContainsKey(key))
172115
{
173116
AddKey(key, val.ToString(), items, goodKeys, badKeys);
174117
}
175-
176118
}
177119
catch (Exception)
178120
{
179-
121+
// ignored
180122
}
181123
}
182124

@@ -185,25 +127,24 @@ internal static Dictionary<string, string> ToKeyValues(IEnumerable<KeyValuePair<
185127

186128
internal static Dictionary<string, string> ToKeyValues(IEnumerable<KeyValuePair<string, string>> collection, List<string> goodKeys, List<string> badKeys)
187129
{
188-
//var keys = collection.Keys;
189130
var items = new Dictionary<string, string>();
190131

191-
foreach (var item in collection)
132+
foreach (KeyValuePair<string, string> item in collection)
192133
{
193-
string key = item.Key;
134+
var key = item.Key;
135+
194136
try
195137
{
196138
object val = item.Value;
197139

198-
if (val != null && !string.IsNullOrWhiteSpace(val.ToString()) && items.ContainsKey(key))
140+
if (val != null && string.IsNullOrWhiteSpace(val.ToString()) == false && items.ContainsKey(key))
199141
{
200142
AddKey(key, val.ToString(), items, goodKeys, badKeys);
201143
}
202-
203144
}
204145
catch (Exception)
205146
{
206-
147+
// ignored
207148
}
208149
}
209150

@@ -218,14 +159,15 @@ internal static void AddKey(string key, string value, Dictionary<string, string>
218159
dictionary[key] = "X-MASKED-X";
219160
return;
220161
}
162+
221163
//if not in the good key list, return
222164
//if good key list is empty, we let it take it
223-
else if (goodKeys != null && goodKeys.Any() && !goodKeys.Any(x => x.Equals(key, StringComparison.CurrentCultureIgnoreCase)))
165+
if (goodKeys != null && goodKeys.Any() && goodKeys.Any(x => x.Equals(key, StringComparison.CurrentCultureIgnoreCase)) == false)
224166
{
225167
return;
226168
}
227169

228170
dictionary[key] = value;
229171
}
230172
}
231-
}
173+
}

Diff for: Src/StackifyLib.CoreLogger/LoggingExtensions.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using Microsoft.Extensions.Logging;
63

74
namespace StackifyLib.CoreLogger
@@ -11,10 +8,12 @@ public static class LoggingExtensions
118
public static ILoggerFactory AddStackify(this ILoggerFactory factory, ILogger logger = null, bool dispose = false)
129
{
1310
if (factory == null)
11+
{
1412
throw new ArgumentNullException("factory");
13+
}
1514

16-
factory.AddProvider((ILoggerProvider)new StackifyLoggerProvider());
15+
factory.AddProvider(new StackifyLoggerProvider());
1716
return factory;
1817
}
1918
}
20-
}
19+
}

Diff for: Src/StackifyLib.CoreLogger/StackifyLib.CoreLogger.csproj

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>Stackify .NET Core LoggerFactory</AssemblyTitle>
5-
<VersionPrefix>2.0.0</VersionPrefix>
6-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<VersionPrefix>2.1.0</VersionPrefix>
6+
<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
77
<AssemblyName>StackifyLib.CoreLogger</AssemblyName>
88
<PackageId>StackifyLib.CoreLogger</PackageId>
99
<PackageTags>stackify;metrics;errors;logs</PackageTags>
@@ -16,14 +16,13 @@
1616
<RepositoryType>git</RepositoryType>
1717
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>
1818
<Description>StackifyLib.CoreLogger</Description>
19-
<Version>2.1.0</Version>
19+
<Version>2.1.1</Version>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
2323
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
2424
</ItemGroup>
2525

26-
2726
<ItemGroup>
2827
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" />
2928
</ItemGroup>

0 commit comments

Comments
 (0)