Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Mar 31, 2017
1 parent 8b5d172 commit d0b85a6
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog.Layouts;
using NLog.Web.Tests.LayoutRenderers;
using Xunit;

namespace NLog.Web.AspNetCore.Tests.LayoutRenderers
{
public class AssemblyVersionLayoutRendererTests : TestBase
{
[Fact]
public void AssemblyNameVersionTest()
{
#if NETSTANDARD_1plus
Layout l = "${assembly-version:NLog.Web.AspNetCore.Tests}";
#else
Layout l = "${assembly-version:NLog.Web.AspNetCore.Tests}";
#endif
var result = l.Render(LogEventInfo.CreateNullEvent());
Assert.Equal("1.2.3.0", result);
}
}
}
1 change: 1 addition & 0 deletions NLog.Web.AspNetCore.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NLog.Web.AspNetCore.Tests")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.2.3.0")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
54 changes: 28 additions & 26 deletions NLog.Web.AspNetCore.Tests/project.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"NLog/5.0.0-beta04": {
"NLog/5.0.0-beta05": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0",
Expand Down Expand Up @@ -974,12 +974,12 @@
"lib/netstandard1.5/NLog.dll": {}
}
},
"NLog.Extensions.Logging/1.0.0-rtm-alpha5": {
"NLog.Extensions.Logging/1.0.0-rtm-beta3": {
"type": "package",
"dependencies": {
"Microsoft.AspNetCore.Hosting": "1.0.0",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"NLog": "5.0.0-beta03"
"NLog": "5.0.0-beta05",
"System.AppContext": "4.3.0"
},
"compile": {
"lib/netstandard1.3/NLog.Extensions.Logging.dll": {}
Expand Down Expand Up @@ -1172,10 +1172,10 @@
"lib/netstandard1.0/_._": {}
}
},
"System.AppContext/4.1.0": {
"System.AppContext/4.3.0": {
"type": "package",
"dependencies": {
"System.Runtime": "4.1.0"
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.6/System.AppContext.dll": {}
Expand Down Expand Up @@ -3270,16 +3270,17 @@
"lib/netstandard1.1/xunit.runner.utility.dotnet.dll": {}
}
},
"NLog.Web.AspNetCore/4.3.0": {
"NLog.Web.AspNetCore/4.3.2": {
"type": "project",
"framework": ".NETStandard,Version=v1.3",
"dependencies": {
"Microsoft.AspNetCore.Hosting": "1.0.0",
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0",
"Microsoft.AspNetCore.Routing.Abstractions": "1.0.0",
"NLog": "5.0.0-beta04",
"NLog.Extensions.Logging": "1.0.0-rtm-alpha5"
"Microsoft.Extensions.PlatformAbstractions": "1.0.0",
"NLog": "5.0.0-beta05",
"NLog.Extensions.Logging": "1.0.0-rtm-beta3"
},
"compile": {
"netstandard1.3/NLog.Web.AspNetCore.dll": {}
Expand Down Expand Up @@ -4085,12 +4086,12 @@
"tools/install.ps1"
]
},
"NLog/5.0.0-beta04": {
"sha512": "kba9JT0qE8sLbBvTa6zxxh4sNLGdgWhQLuzFid/5vpakLuASIc2yI8b7yo+YTB5ZWM8vQDqIUQcFfuCgXYY99Q==",
"NLog/5.0.0-beta05": {
"sha512": "w8o0ZjF/8qM8eOrm8PtfE0AJv+huOt3T3C7EjUfao1whmqRTTAcTDCELwA3O6WG6ErYzqQnciUeRUEpM/OvWMA==",
"type": "package",
"path": "NLog/5.0.0-beta04",
"path": "NLog/5.0.0-beta05",
"files": [
"NLog.5.0.0-beta04.nupkg.sha512",
"NLog.5.0.0-beta05.nupkg.sha512",
"NLog.nuspec",
"lib/monoandroid23/NLog.dll",
"lib/monoandroid23/NLog.xml",
Expand All @@ -4114,15 +4115,16 @@
"lib/xamarinios10/NLog.xml"
]
},
"NLog.Extensions.Logging/1.0.0-rtm-alpha5": {
"sha512": "EAyWzB2J1CbsLoXyeVDZRiiJ0gmnvkssnq3M7r6DHrtkqXyowCcnqLg+na0FYWQrVLcenmoJ+Lo466GHZ7RJ4A==",
"NLog.Extensions.Logging/1.0.0-rtm-beta3": {
"sha512": "ZJNBeEAGK9uAYUzZsNo3Ow6ABWCC6lrTPbcw4bX7TZr7plSJQtuMlnPDUNFxlzGdHLhubC3otbbSwVjb5R3ypQ==",
"type": "package",
"path": "NLog.Extensions.Logging/1.0.0-rtm-alpha5",
"path": "NLog.Extensions.Logging/1.0.0-rtm-beta3",
"files": [
"NLog.Extensions.Logging.1.0.0-rtm-alpha5.nupkg.sha512",
"NLog.Extensions.Logging.nuspec",
"lib/net451/NLog.Extensions.Logging.dll",
"lib/netstandard1.3/NLog.Extensions.Logging.dll"
"lib/net451/NLog.Extensions.Logging.xml",
"lib/netstandard1.3/NLog.Extensions.Logging.dll",
"nlog.extensions.logging.1.0.0-rtm-beta3.nupkg.sha512",
"nlog.extensions.logging.nuspec"
]
},
"NSubstitute/2.0.0-alpha003": {
Expand Down Expand Up @@ -4290,12 +4292,12 @@
"runtime.native.System.Security.Cryptography.nuspec"
]
},
"System.AppContext/4.1.0": {
"sha512": "3QjO4jNV7PdKkmQAVp9atA+usVnKRwI3Kx1nMwJ93T0LcQfx7pKAYk0nKz5wn1oP5iqlhZuy6RXOFdhr7rDwow==",
"System.AppContext/4.3.0": {
"sha512": "JNZqGL1GEa2YvWFsqDA308vTIQmdTXNYISX56DGMKDMudASGBpQTiQY51/oxJc/gNOShXWTs+/Lck2KYPz/j3Q==",
"type": "package",
"path": "System.AppContext/4.1.0",
"path": "System.AppContext/4.3.0",
"files": [
"System.AppContext.4.1.0.nupkg.sha512",
"System.AppContext.4.3.0.nupkg.sha512",
"System.AppContext.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
Expand Down Expand Up @@ -9083,7 +9085,7 @@
"xunit.runner.utility.nuspec"
]
},
"NLog.Web.AspNetCore/4.3.0": {
"NLog.Web.AspNetCore/4.3.2": {
"type": "project",
"path": "../NLog.Web.AspNetCore/project.json",
"msbuildProject": "../NLog.Web.AspNetCore/NLog.Web.AspNetCore.xproj"
Expand All @@ -9094,8 +9096,8 @@
"Microsoft.AspNetCore.Hosting.Abstractions >= 1.0.0",
"Microsoft.AspNetCore.Http.Extensions >= 1.0.0",
"Microsoft.AspNetCore.Routing.Abstractions >= 1.0.0",
"NLog >= 5.0.0-beta04",
"NLog.Web.AspNetCore >= 4.3.0",
"NLog >= 5.0.0-beta05",
"NLog.Web.AspNetCore >= 4.3.2",
"NSubstitute >= 2.0.0-alpha003",
"dotnet-test-xunit >= 2.2.0-preview2-build1029",
"xunit >= 2.2.0-beta2-build3300"
Expand Down
101 changes: 101 additions & 0 deletions NLog.Web.AspNetCore/LayoutRenderers/AssemblyVersionLayoutRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using NLog.Common;
using NLog.Config;
using NLog.LayoutRenderers;

#if NETSTANDARD_1plus
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.PlatformAbstractions;
#endif

namespace NLog.Web.LayoutRenderers
{
/// <summary>
/// Overwrite the NLog.LayoutRenderers.AssemblyVersionLayoutRenderer
/// </summary>
[LayoutRenderer("assembly-version")]
public class AssemblyVersionLayoutRenderer : LayoutRenderer
{
/// <summary>
/// The (full) name of the assembly. If <c>null</c>, using the entry assembly.
/// </summary>
[DefaultParameter]
public string Name { get; set; }

/// <summary>
/// Implemented by subclasses to render request information and append it to the specified <see cref="StringBuilder" />.
///
/// Won't be called if <see cref="AspNetLayoutRendererBase.HttpContextAccessor"/> of <see cref="IHttpContextAccessor.HttpContext"/> is <c>null</c>.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
InternalLogger.Trace("Using ${assembly-version} of NLog.Web");

var nameNotEmpty = !string.IsNullOrEmpty(Name);
if (nameNotEmpty)
{
var assembly = Assembly.Load(new AssemblyName(Name));
if (assembly == null)
{
builder.Append("Could not find assembly " + Name);
}
else
{
builder.Append(assembly.GetName().Version.ToString());
}
}
else
{
//try entry assembly

#if NETSTANDARD_1plus
string assemblyVersion = PlatformServices.Default.Application.RuntimeFramework.Version.ToString();

builder.Append(assemblyVersion);
#else

var assembly = Assembly.GetEntryAssembly();

if (assembly == null)
{
assembly = GetAspNetEntryAssembly();
}
if (assembly == null)
{
builder.Append("Could not entry assembly");
}
else
{
builder.Append(assembly.GetName().Version.ToString());
}
#endif

}

}

#if !NETSTANDARD_1plus
private static Assembly GetAspNetEntryAssembly()
{
if (System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.ApplicationInstance == null)
{
return null;
}
var type = System.Web.HttpContext.Current.ApplicationInstance.GetType();
while (type != null && type.Namespace == "ASP")
{
type = type.BaseType;
}
return type != null ? type.Assembly : null;
}
#endif
}
}
44 changes: 23 additions & 21 deletions NLog.Web.AspNetCore/project.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{

"version": "4.3.2",
"description": "Extend NLog with targets and layout renderers for websites and webapplications on the ASP.NET Core platform.",
"authors": [ "Julian Verdurmen" ],
"packOptions": {
"summary": "NLog for ASP.NET Core",
"description": "Extend NLog with targets and layout renderers for websites and webapplications on the ASP.NET Core platform.",
"authors": [ "Julian Verdurmen" ],
"packOptions": {
"summary": "NLog for ASP.NET Core",
"tags": [ "logging", "log", "session", "NLog", "web", "aspnet", "aspnetcore", "MVC" ],
"projectUrl": "https://github.com/NLog/NLog.Web",
"licenseUrl": "http://raw.github.com/NLog/NLog.Web/master/LICENSE",
"requireLicenseAcceptance": false,
"iconUrl": "http://nlog-project.org/N.png",
"repository": {
"type": "git",
"url": "git://github.com/NLog/NLog.Web"
"projectUrl": "https://github.com/NLog/NLog.Web",
"licenseUrl": "http://raw.github.com/NLog/NLog.Web/master/LICENSE",
"requireLicenseAcceptance": false,
"iconUrl": "http://nlog-project.org/N.png",
"repository": {
"type": "git",
"url": "git://github.com/NLog/NLog.Web"
},
"releaseNotes":"Update dependencies"
},
Expand All @@ -22,18 +22,20 @@
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0",
"Microsoft.AspNetCore.Routing.Abstractions": "1.0.0",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0",
"NLog": "5.0.0-beta05",
"NLog.Extensions.Logging": "1.0.0-rtm-beta3"

},

"title": "NLog.Web.AspNetCore",
"frameworks": {
"netstandard1.3": {},
"net451": {}
},
"buildOptions": {
"keyFile": "NLog.snk",
"xmlDoc": true,
"define": [ "NETSTANDARD_1plus" ]
}
"title": "NLog.Web.AspNetCore",
"frameworks": {
"netstandard1.3": { },
"net451": { }
},
"buildOptions": {
"keyFile": "NLog.snk",
"xmlDoc": true,
"define": [ "NETSTANDARD_1plus" ]
}
}

0 comments on commit d0b85a6

Please sign in to comment.