[LayoutRenderer("hello-world")]
public class HelloWorldLayoutRenderer : LayoutRenderer
{
/// <summary>
/// I'm option and not required or default
/// </summary>
public string Config1 { get; set; }
/// <summary>
/// I'm required option. And error will be thrown if not set.
/// </summary>
[RequiredParameter]
public string Config2 { get; set; }
/// <summary>
/// I'm the default parameter.
/// The first parameter value (without name) will be set to this one
/// You can set me as required also.
/// </summary>
[DefaultParameter]
public bool Caps {get;set;}
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
//TODO use options
builder.Append("hello world!");
}
}
Register - as soon as possible - e.g. in main()
, application_start()
.
//register under "hello-world"
ConfigurationItemFactory.Default.LayoutRenderers
.RegisterDefinition("hello-world", typeof(MyNamespace.HelloWorldLayoutRenderer ));
Usage
${hello-world} - raises exception: required parameter Config2 isn't set
${hello-world:Config2=abc} - OK, Config2 property set
${hello-world:true:config2=abc} - default parameter (Caps) set to true
${hello-world:true:config2=abc:config1=yes} - all the three properties set.