Sha256: 40f849aff7cd06b3f05abc04715427ed3bd53f3780424d5116e4b1e79468991d

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

using System;
using System.Text;

using NLog;

namespace MyNamespace
{
    [LayoutRenderer("hour")]
    public sealed class HourLayoutRenderer: LayoutRenderer
    {
        private bool _showMinutes = false;
        
        // this is an example of a configurable parameter
        public bool ShowMinutes
        {
            get { return _showMinutes; }
            set { _showMinutes = value; }
            
        }
        protected override int GetEstimatedBufferSize(LogEventInfo ev)
        {
            // since hour is expressed by 2 digits we need at most 2-character
            // buffer for it
            return 2;
        }

        protected override void Append(StringBuilder builder, LogEventInfo ev)
        {
            // get current hour or minute, convert it to string, apply padding
            // and append to the specified StringBuilder
            if (ShowMinutes)
            {
                builder.Append(ApplyPadding(DateTime.Now.Minute.ToString()));
            }
            else
            {
                builder.Append(ApplyPadding(DateTime.Now.Hour.ToString()));
            }
        }
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nlog-1.0.0.505.20100822 docs/examples/web/MyFirstLayoutRenderer.cs
nlog-1.0.0.505 docs/examples/web/MyFirstLayoutRenderer.cs
nlog-1.0.0.505-mswin32 docs/examples/web/MyFirstLayoutRenderer.cs