-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f0ac4
commit 850f479
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |