Skip to content

Commit

Permalink
NlcLayoutRenderer - Nested Logical Context
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed May 16, 2017
1 parent 0772326 commit 732b560
Show file tree
Hide file tree
Showing 19 changed files with 638 additions and 6 deletions.
85 changes: 85 additions & 0 deletions src/NLog/LayoutRenderers/NlcLayoutRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// Copyright (c) 2004-2016 Jaroslaw Kowalski <jaak@jkowalski.net>, Kim Christensen, Julian Verdurmen
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of Jaroslaw Kowalski nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//

namespace NLog.LayoutRenderers
{
#if NET4_0 || NET4_5
using System;
using System.Text;

/// <summary>
/// Nested Logical Context Renderer (Async scope)
/// </summary>
[LayoutRenderer("nlc")]
public class NlcLayoutRenderer : LayoutRenderer
{
/// <summary>
/// Initializes a new instance of the <see cref="NlcLayoutRenderer" /> class.
/// </summary>
public NlcLayoutRenderer()
{
this.Separator = " ";
this.BottomFrames = -1;
this.TopFrames = -1;
}

/// <summary>
/// Gets or sets the number of top stack frames to be rendered.
/// </summary>
/// <docgen category='Rendering Options' order='10' />
public int TopFrames { get; set; }

/// <summary>
/// Gets or sets the number of bottom stack frames to be rendered.
/// </summary>
/// <docgen category='Rendering Options' order='10' />
public int BottomFrames { get; set; }

/// <summary>
/// Gets or sets the separator to be used for concatenating nested logical context output.
/// </summary>
/// <docgen category='Rendering Options' order='10' />
public string Separator { get; set; }

/// <summary>
/// Renders the specified Nested Logical Context item and appends it to the specified <see cref="StringBuilder" />.
/// </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)
{
NestedLogicalContext.AppendContext(logEvent.FormatProvider, this.TopFrames, this.BottomFrames, this.Separator, builder);
}
}
#endif
}
2 changes: 2 additions & 0 deletions src/NLog/NLog.Xamarin.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -348,6 +349,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.Xamarin.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -345,6 +346,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.doc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -358,6 +359,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -364,6 +365,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -358,6 +359,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -358,6 +359,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -363,6 +364,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.sl4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -365,6 +366,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.sl5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -362,6 +363,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.wp7.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -361,6 +362,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.wp71.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -361,6 +362,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.wp8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<Compile Include="LayoutRenderers\MessageLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NdcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NewLineLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NlcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\NLogDirLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\PerformanceCounterLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ProcessIdLayoutRenderer.cs" />
Expand Down Expand Up @@ -386,6 +387,7 @@
<Compile Include="MDC.cs" />
<Compile Include="NDC.cs" />
<Compile Include="NestedDiagnosticsContext.cs" />
<Compile Include="NestedLogicalContext.cs" />
<Compile Include="NLogConfigurationException.cs" />
<Compile Include="NLogRuntimeException.cs" />
<Compile Include="NLogTraceListener.cs" />
Expand Down
Loading

0 comments on commit 732b560

Please sign in to comment.