Skip to content

Commit

Permalink
Merge pull request #125 from NLog/grokky1-patch-1
Browse files Browse the repository at this point in the history
fix ${iis-site-name} for ASP.NET Core, move IHostingEnvironment.EnvironmentName to ${aspnet-environment}
  • Loading branch information
304NotModified authored Mar 31, 2017
2 parents 2ab8049 + 850f479 commit 8b5d172
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if NETSTANDARD_1plus
using System;
using System.Text;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using NLog.LayoutRenderers;
using NLog.Web.Internal;

namespace NLog.Web.LayoutRenderers
{

/// <summary>
/// Rendering development environment. <see cref="IHostingEnvironment"/>
/// </summary>
[LayoutRenderer("aspnet-environment")]
// ReSharper disable once InconsistentNaming
public class AspNetEnvironmentLayoutRenderer : LayoutRenderer
{
/// <summary>
/// Append to target
/// </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)
{
var env = ServiceLocator.ServiceProvider?.GetService<IHostingEnvironment>();
builder.Append(env?.EnvironmentName);
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)

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

#else
builder.Append(HostingEnvironment.SiteName);
Expand Down

0 comments on commit 8b5d172

Please sign in to comment.