Skip to content

Commit

Permalink
Upgrade to ASP.NET Core, including sessionId
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed May 23, 2016
1 parent 5206477 commit e8c50d0
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 402 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -181,3 +181,6 @@ UpgradeLog*.htm

# Microsoft Fakes
FakesAssemblies/

#VS folder
.vs
2 changes: 1 addition & 1 deletion .vs/restore.dg
@@ -1 +1 @@
#:X:\Github-nlog-production\NLog.Web\NLog.Web.AspNet.Core\NLog.Web.AspNet.Core.xproj
#:X:\Github-nlog-production\NLog.Web\NLog.Web.AspNetCore\NLog.Web.AspNetCore.xproj
6 changes: 2 additions & 4 deletions NLog.Web.AspNetCore/DefaultHttpContextAccessor.cs
@@ -1,16 +1,14 @@
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;

#endif



namespace NLog.Web
{
#if !DNX
#if !NETSTANDARD_1plus
/// <summary>
/// Provides the HttpContext associated with the current request.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/IHttpContextAccessor.cs
@@ -1,4 +1,4 @@
#if !DNX
#if !NETSTANDARD_1plus

using System;
using System.Web;
Expand Down
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/Internal/PropertyReader.cs
Expand Up @@ -43,7 +43,7 @@ public static object GetValue(string key, Func<string, object> getVal, bool eval

private static PropertyInfo GetPropertyInfo(object value, string propertyName)
{
#if !DNX
#if !NETSTANDARD_1plus
return value.GetType().GetProperty(propertyName);
#else
return value.GetType().GetTypeInfo().GetDeclaredProperty(propertyName);
Expand Down
@@ -1,4 +1,4 @@
#if !DNX
#if !NETSTANDARD_1plus

using System;
using System.Globalization;
Expand Down
Expand Up @@ -2,11 +2,9 @@
using System.Globalization;
using System.Linq;
using System.Text;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
#endif
using NLog.Config;
using NLog.LayoutRenderers;
Expand Down
@@ -1,10 +1,9 @@
using System;
using System.Text;
using NLog.LayoutRenderers;
#if DNX
#if NETSTANDARD_1plus
using NLog.Web.Internal;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
#endif

Expand All @@ -20,13 +19,13 @@ public abstract class AspNetLayoutRendererBase : LayoutRenderer
/// </summary>
protected AspNetLayoutRendererBase()
{
#if !DNX
#if !NETSTANDARD_1plus
HttpContextAccessor = new DefaultHttpContextAccessor();
#endif
}


#if DNX
#if NETSTANDARD_1plus

/// <summary>
/// Context for DI
Expand Down
@@ -1,11 +1,10 @@
using System;
using System.Text;
#if !NETSTANDARD_1plus
using NLog.Common;
#if !DNX
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
#endif
using NLog.Config;
using NLog.LayoutRenderers;
Expand Down Expand Up @@ -85,7 +84,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)

if (this.QueryString != null)
{
#if !DNX
#if !NETSTANDARD_1plus
builder.Append(httpRequest.QueryString[this.QueryString]);
#else
builder.Append(httpRequest.Query[this.QueryString]);
Expand All @@ -97,7 +96,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}
else if (this.Cookie != null)
{
#if !DNX
#if !NETSTANDARD_1plus
var cookie = httpRequest.Cookies[this.Cookie];

if (cookie != null)
Expand All @@ -112,7 +111,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}
else if (this.ServerVariable != null)
{
#if !DNX
#if !NETSTANDARD_1plus
builder.Append(httpRequest.ServerVariables[this.ServerVariable]);
#else

Expand All @@ -130,7 +129,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}
else if (this.Item != null)
{
#if !DNX
#if !NETSTANDARD_1plus
builder.Append(httpRequest[this.Item]);
#else
builder.Append(httpRequest.HttpContext.Items[this.Item]);
Expand All @@ -141,7 +140,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)

internal static class RequestAccessor
{
#if !DNX
#if !NETSTANDARD_1plus
internal static HttpRequestBase TryGetRequest(this HttpContextBase context)
{
try
Expand Down
@@ -1,13 +1,11 @@
using System.Text;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;

#endif
using NLog.LayoutRenderers;

#if !DNX
namespace NLog.Web.LayoutRenderers
{
/// <summary>
Expand All @@ -16,14 +14,6 @@ namespace NLog.Web.LayoutRenderers
[LayoutRenderer("aspnet-sessionid")]
public class AspNetSessionIDLayoutRenderer : AspNetLayoutRendererBase
{
#if DNX
/// <summary>
/// Initializes the <see cref="AspNetSessionIDLayoutRenderer"/> with the <see cref="IHttpContextAccessor"/>.
/// </summary>
public AspNetSessionIDLayoutRenderer(IHttpContextAccessor accessor) : base(accessor)
{
}
#endif
/// <summary>
/// Renders the ASP.NET Session ID appends it to the specified <see cref="StringBuilder" />.
/// </summary>
Expand All @@ -37,9 +27,11 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
return;
}

#if !NETSTANDARD_1plus
builder.Append(context.Session.SessionID);
#else
builder.Append(context.Session.Id);
#endif
}
}
}
#endif
Expand Up @@ -2,13 +2,12 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using NLog.Common;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http;
#endif
using NLog.Config;
using NLog.LayoutRenderers;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
return;
}
#if !DNX
#if !NETSTANDARD_1plus
var value = PropertyReader.GetValue(Variable, k => context.Session[k], EvaluateAsNestedProperties);
#else
if (context.Items == null)
Expand All @@ -96,7 +95,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
//prevent stackoverflow
return;
}

context.Items[NLogRetrievingSessionValue] = true;
object value;
try
Expand All @@ -105,8 +104,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}
catch (Exception ex)
{
//TODO change this call for NLog 4.3
InternalLogger.Warn("Retrieving session value failed. " + ex);
InternalLogger.Warn(ex, "Retrieving session value failed. ");
return;
}
finally
Expand Down
@@ -1,9 +1,7 @@
using System.Text;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
#endif
using NLog.LayoutRenderers;

Expand Down
@@ -1,9 +1,7 @@
using System.Text;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
#endif
using NLog.LayoutRenderers;

Expand Down
@@ -1,26 +1,30 @@
using System;
using System.Text;
#if !DNX
#if !NETSTANDARD_1plus
using System.Web.Hosting;
#else
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
#endif
using NLog.LayoutRenderers;
using NLog.Web.Internal;

namespace NLog.Web.LayoutRenderers
{

#if NETSTANDARD_1plus
/// <summary>
/// Rendering site name in IIS. <see cref="IHostingEnvironment"/>
/// </summary>
#else
/// <summary>
/// IIS site name - printing <see cref="HostingEnvironment.SiteName"/>
/// Rendering site name in IIS. <see cref="HostingEnvironment.SiteName"/>
/// </summary>
#endif
[LayoutRenderer("iis-site-name")]
// ReSharper disable once InconsistentNaming
public class IISInstanceNameLayoutRenderer : LayoutRenderer
{


/// <summary>
/// Append to target
/// </summary>
Expand All @@ -30,7 +34,7 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{


#if DNX
#if NETSTANDARD_1plus
var env = ServiceLocator.ServiceProvider?.GetService<IHostingEnvironment>();
builder.Append(env?.EnvironmentName);

Expand Down
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/NLogHttpModule.cs
@@ -1,4 +1,4 @@
#if !DNX
#if !NETSTANDARD_1plus
using System;
using System.Web;

Expand Down
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/Targets/AspNetTrace.cs
@@ -1,5 +1,5 @@

#if !DNX
#if !NETSTANDARD_1plus
using System.Web;
using NLog.Targets;

Expand Down
@@ -1,4 +1,4 @@
#if !DNX
#if !NETSTANDARD_1plus
using System;
using System.ComponentModel;
using System.Web;
Expand Down
8 changes: 5 additions & 3 deletions NLog.Web.AspNetCore/project.json
Expand Up @@ -21,16 +21,18 @@
"frameworks": {

"netstandard1.3": {
"buildOptions": { "define": [ "DOTNET5_4", "DNX451", "DNX" ] },
"buildOptions": { "define": [ "NETSTANDARD_1plus" ] },
"dependencies": {
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0-rc2-final",
"NLog": "4.4.0-beta8"
}
}


},
"buildOptions": {
"keyFile": "NLog.snk"
"keyFile": "NLog.snk",
"xmlDoc": true
}
}

0 comments on commit e8c50d0

Please sign in to comment.