-
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.
Merge pull request #125 from NLog/grokky1-patch-1
fix ${iis-site-name} for ASP.NET Core, move IHostingEnvironment.EnvironmentName to ${aspnet-environment}
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
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 |
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