The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Cankut Eskin
 |
| 06/22/2009 3:09 PM |
|
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
|
|
|
|
|
Ron Grabowski
 |
| 06/22/2009 11:22 PM |
|
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.
|
|
|
|
|
Ron Grabowski
 |
| 06/22/2009 11:44 PM |
|
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>
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|