Skip to content

Commit

Permalink
Add aspnet-environment
Browse files Browse the repository at this point in the history
  • Loading branch information
grokky1 authored and 304NotModified committed Mar 31, 2017
1 parent e3f0ac4 commit 850f479
Showing 1 changed file with 31 additions and 0 deletions.
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

0 comments on commit 850f479

Please sign in to comment.