Whoops, I re-read your post and saw that you wanted to output both the hostname
and the message at the same time. In that case you'd probably want to continue
using the PatternLayout and register a special converter:
public class HostNameToUpperConverter : PatternConverter
{
protected override void Convert(TextWriter writer, object state)
{
string hostName =
(string)GlobalContext.Properties[LoggingEvent.HostNameProperty];
writer.Write(hostName.ToUpper());
}
}
<layout type="log4net.Layout.PatternLayout">
<converter>
<name value="hostNameToUpper" />
<type value="ConsoleApplication1.HostNameToUpperConverter,
ConsoleApplication1" />
</converter>
<conversionPattern value="[%hostNameToUpper] - %message" />
</layout>
________________________________
From: Ron Grabowski <[email protected]>
To: Log4NET User <[email protected]>
Sent: Monday, June 22, 2009 5:22:26 PM
Subject: Re: How to make a part of log message uppercase
This should work:
// untested
public class HostNameToUpperLayout : LayoutSkeleton
{
public override void ActivateOptions()
{
// empty
}
public override void Format(TextWriter writer, LoggingEvent loggingEvent)
{
string hostName =
(string)loggingEvent.LookupProperty("log4net:HostName");
writer.Write(hostName.ToUpper());
}
}
<parameter>
<parameterName value="@message"/>
<dbType value="String"/>
<size value="4000"/>
<layout type="Company.Application.HostNameToUpperLayout,
Company.Application" />
</parameter>
There are more clever ways of doing it but that should work.
________________________________
From: Cankut Eskin <[email protected]>
To: Log4NET User <[email protected]>
Sent: Monday, June 22, 2009 9:09:37 AM
Subject: How to make a part of log message uppercase
Hello,
I'm using AdoNetAppender to log messages. I've added
%property{log4net:HostName} conversion pattern to the message parameter.
<parameter>
<parameterName value="@message"/>
<dbType value="String"/>
<size value="4000"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%property{log4net:HostName}] - %message"/>
</layout>
</parameter>
Output is like
[hostname] - foo bar.
But i want the output like
[HOSTNAME] - foo bar.
How can i make the hostname uppercase using conversion patterns?
Regards,
Cankut