From 850f4793c05c46ce987b6bff6072028b1bb94d97 Mon Sep 17 00:00:00 2001 From: grokky1 Date: Thu, 30 Mar 2017 23:41:26 +0200 Subject: [PATCH] Add aspnet-environment --- .../AspNetEnvironmentLayoutRenderer.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs diff --git a/NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs b/NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs new file mode 100644 index 00000000..2165c959 --- /dev/null +++ b/NLog.Web.AspNetCore/LayoutRenderers/AspNetEnvironmentLayoutRenderer.cs @@ -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 +{ + + /// + /// Rendering development environment. + /// + [LayoutRenderer("aspnet-environment")] + // ReSharper disable once InconsistentNaming + public class AspNetEnvironmentLayoutRenderer : LayoutRenderer + { + /// + /// Append to target + /// + /// The to append the rendered data to. + /// Logging event. + protected override void Append(StringBuilder builder, LogEventInfo logEvent) + { + var env = ServiceLocator.ServiceProvider?.GetService(); + builder.Append(env?.EnvironmentName); + } + } +} +#endif \ No newline at end of file