|
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()));
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.