StackTrace return Null in Nlog Custom Layout Render

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

StackTrace return Null in Nlog Custom Layout Render

ZeusSE
This post was updated on .
i have this Layout Render:

    [LayoutRenderer("IndentationLayout")]
public sealed class IndentationLayoutRenderer : LayoutRenderer
{
    // Value to substract from stack count
    private uint _ignore = 3;

    // Value to pad with.
    private string _ipadding = "| ";

    /// <summary>Set the number of (top) stackframes to ignore</summary>
    public uint Ignore
    {
        get { return _ignore; }
        set { _ignore = value; }
    }

    /// <summary>Set the padding value</summary>
    public string IndentationPadding
    {
        get { return _ipadding; }
        set { _ipadding = value; }
    }

    protected override void Append(StringBuilder builder, LogEventInfo ev)
    {
        // Get current stack depth, insert padding chars.
        long indent = ev.StackTrace.FrameCount;
        indent = indent > _ignore ? indent - _ignore : 0;
        for (int i = 0; i < indent; ++i)
        {
            builder.Append(_ipadding);
        }
    }
}

i tried to register it using this:


NLog.Config.ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("IndentationLayout", typeof(IndentationLayoutRenderer));

but when i run the app it gives me this:
Object reference not set to an instance of an object.
on
long indent = ev.StackTrace.FrameCount;

cause StackTrace is null


any idea why this is happening ?how can i fix that ?


im using Nlog 2
and .netframework 4
visual studio 2010.

in a Console Application Project.
Reply | Threaded
Open this post in threaded view
|

Re: Registering Nlog Custom Layout Render

Jarek Kowalski
Administrator
Can you post your config?

You should be using ${indentation}.

Jarek
NLog Blog