Monday, May 21, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

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.

Subject: How to make a part of log message uppercase
Prev Next
You are not authorized to post a reply.

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.
Forums > Log4Net > Log4Net Mail archive > How to make a part of log message uppercase



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement