Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Src/CoreConsoleApp/CoreConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>CoreConsoleApp</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>CoreConsoleApp</PackageId>
Expand All @@ -27,11 +27,11 @@
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' OR '$(TargetFramework)' == 'net452' OR '$(TargetFramework)' == 'net46' ">
<DefineConstants>NETFULL</DefineConstants>
</PropertyGroup>
Expand Down
3 changes: 0 additions & 3 deletions Src/CoreConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace CoreConsoleApp
{
public class Program
{



static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
Expand Down
9 changes: 3 additions & 6 deletions Src/StackifyLib.AspNetCore/Configure.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using StackifyLib.Models;

namespace StackifyLib.AspNetCore
{
internal class Configure
{

internal static IServiceProvider ServiceProvider { get; set; }

internal static void SubscribeToWebRequestDetails(IServiceProvider serviceProvider)
{
if (ServiceProvider != null)
{
return;
}

ServiceProvider = serviceProvider;

WebRequestDetail.SetWebRequestDetail += WebRequestDetailMapper.WebRequestDetail_SetWebRequestDetail;
}
}

}
}
13 changes: 3 additions & 10 deletions Src/StackifyLib.AspNetCore/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using StackifyLib.AspNetCore;

namespace StackifyLib
{
public static class Extensions
{



public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IApplicationBuilder app,
Microsoft.Extensions.Configuration.IConfigurationRoot configuration)
public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.Extensions.Configuration.IConfigurationRoot configuration)
{
try
{
Expand All @@ -29,8 +22,8 @@ public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IA
}
catch (Exception ex)
{
Debug.WriteLine("Error in AddStackifyLogging " + ex.ToString());
Debug.WriteLine($"Error in ConfigureStackifyLogging {ex}");
}
}
}
}
}
6 changes: 3 additions & 3 deletions Src/StackifyLib.AspNetCore/StackifyLib.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<AssemblyTitle>StackifyLib for AspNetCore</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<VersionPrefix>2.1.0</VersionPrefix>
<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
<AssemblyName>StackifyLib.AspNetCore</AssemblyName>
<PackageId>StackifyLib.AspNetCore</PackageId>
<PackageTags>stackify;metrics;errors;logs</PackageTags>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Description>StackifyLib.AspNetCore</Description>
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
Expand Down
118 changes: 30 additions & 88 deletions Src/StackifyLib.AspNetCore/WebRequestDetailMapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using StackifyLib.Models;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives;
using StackifyLib.Models;

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

if (context == null)
{
return;
}

Load(context, detail);
}

private static void Load(HttpContext context, WebRequestDetail detail)
{
if (context == null || context.Request == null)
{
return;
}

HttpRequest request = context.Request;
var request = context.Request;

try
{
detail.HttpMethod = request.Method;

detail.UserIPAddress = context?.Connection?.RemoteIpAddress?.ToString();


//if (context.Items != null && context.Items.Contains("Stackify.ReportingUrl"))
//{
// ReportingUrl = context.Items["Stackify.ReportingUrl"].ToString();
//}


if (request.IsHttps)
{
detail.RequestProtocol = "https";
}
else
{
detail.RequestProtocol = "http";
}
detail.RequestUrl = detail.RequestProtocol + "//" + request.Host + request.Path;


detail.UserIPAddress = context.Connection?.RemoteIpAddress?.ToString();
detail.RequestProtocol = request.IsHttps ? "https" : "http";
detail.RequestUrl = $"{detail.RequestProtocol}//{request.Host}{request.Path}";
detail.MVCAction = context.GetRouteValue("action")?.ToString();
detail.MVCController = context.GetRouteValue("controller")?.ToString();

if (!string.IsNullOrEmpty(detail.MVCAction) && !string.IsNullOrEmpty(detail.MVCController))
if (string.IsNullOrEmpty(detail.MVCAction) == false && string.IsNullOrEmpty(detail.MVCController) == false)
{
detail.ReportingUrl = detail.MVCController + "." + detail.MVCAction;
detail.ReportingUrl = $"{detail.MVCController}.{detail.MVCAction}";
}


//if (request.AppRelativeCurrentExecutionFilePath != null)
//{
// RequestUrlRoot = request.AppRelativeCurrentExecutionFilePath.TrimStart('~');
//}

}
catch (Exception)
{

// ignored
}



try
{

if (request.QueryString != null)
{
detail.QueryString = ToKeyValues(request.Query, null, null);
Expand All @@ -95,12 +70,12 @@ private static void Load(HttpContext context, WebRequestDetail detail)
Config.ErrorHeaderBadKeys = new List<string>();
}

if (!Config.ErrorHeaderBadKeys.Contains("cookie"))
if (Config.ErrorHeaderBadKeys.Contains("cookie") == false)
{
Config.ErrorHeaderBadKeys.Add("cookie");
}

if (!Config.ErrorHeaderBadKeys.Contains("authorization"))
if (Config.ErrorHeaderBadKeys.Contains("authorization") == false)
{
Config.ErrorHeaderBadKeys.Add("authorization");
}
Expand All @@ -117,66 +92,33 @@ private static void Load(HttpContext context, WebRequestDetail detail)
{
detail.PostData = ToKeyValues(request.Form, null, null);
}

//sessions return a byte array...
//if (context.Session != null && Config.CaptureSessionVariables && Config.ErrorSessionGoodKeys.Any())
//{
// SessionData = new Dictionary<string, string>();

// foreach (var key in Config.ErrorSessionGoodKeys)
// {
// SessionData[key] = context.Session
// }


//}

//if (Config.CaptureErrorPostdata)
//{
// var contentType = context.Request.Headers["Content-Type"];

// if (contentType != "text/html" && contentType != "application/x-www-form-urlencoded" &&
// context.Request.RequestType != "GET")
// {
// int length = 4096;
// string postBody = new StreamReader(context.Request.InputStream).ReadToEnd();
// if (postBody.Length < length)
// {
// length = postBody.Length;
// }

// PostDataRaw = postBody.Substring(0, length);
// }
//}
}
catch (Exception)
{
// ignored
}
}

//IEnumerable<KeyValuePair<string, StringValues>>
//IEnumerable<KeyValuePair<string, string>>
internal static Dictionary<string, string> ToKeyValues(IEnumerable<KeyValuePair<string, StringValues>> collection, List<string> goodKeys, List<string> badKeys)
{
//var keys = collection.Keys;
var items = new Dictionary<string, string>();

foreach (var item in collection)
foreach (KeyValuePair<string, StringValues> item in collection)
{
string key = item.Key;
var key = item.Key;

try
{
object val = item.Value.ToString();

if (val != null && !string.IsNullOrWhiteSpace(val.ToString()) && items.ContainsKey(key))
if (val != null && string.IsNullOrWhiteSpace(val.ToString()) == false && items.ContainsKey(key))
{
AddKey(key, val.ToString(), items, goodKeys, badKeys);
}

}
catch (Exception)
{

// ignored
}
}

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

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

foreach (var item in collection)
foreach (KeyValuePair<string, string> item in collection)
{
string key = item.Key;
var key = item.Key;

try
{
object val = item.Value;

if (val != null && !string.IsNullOrWhiteSpace(val.ToString()) && items.ContainsKey(key))
if (val != null && string.IsNullOrWhiteSpace(val.ToString()) == false && items.ContainsKey(key))
{
AddKey(key, val.ToString(), items, goodKeys, badKeys);
}

}
catch (Exception)
{

// ignored
}
}

Expand All @@ -218,14 +159,15 @@ internal static void AddKey(string key, string value, Dictionary<string, string>
dictionary[key] = "X-MASKED-X";
return;
}

//if not in the good key list, return
//if good key list is empty, we let it take it
else if (goodKeys != null && goodKeys.Any() && !goodKeys.Any(x => x.Equals(key, StringComparison.CurrentCultureIgnoreCase)))
if (goodKeys != null && goodKeys.Any() && goodKeys.Any(x => x.Equals(key, StringComparison.CurrentCultureIgnoreCase)) == false)
{
return;
}

dictionary[key] = value;
}
}
}
}
9 changes: 4 additions & 5 deletions Src/StackifyLib.CoreLogger/LoggingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

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

factory.AddProvider((ILoggerProvider)new StackifyLoggerProvider());
factory.AddProvider(new StackifyLoggerProvider());
return factory;
}
}
}
}
7 changes: 3 additions & 4 deletions Src/StackifyLib.CoreLogger/StackifyLib.CoreLogger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<AssemblyTitle>Stackify .NET Core LoggerFactory</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<VersionPrefix>2.1.0</VersionPrefix>
<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
<AssemblyName>StackifyLib.CoreLogger</AssemblyName>
<PackageId>StackifyLib.CoreLogger</PackageId>
<PackageTags>stackify;metrics;errors;logs</PackageTags>
Expand All @@ -16,14 +16,13 @@
<RepositoryType>git</RepositoryType>
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>
<Description>StackifyLib.CoreLogger</Description>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" />
</ItemGroup>
Expand Down
Loading