You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Lars Bjønnes <la...@gmail.com> on 2008/10/02 20:44:52 UTC

Replacing text in log messages

Hello,

I am trying to replace certain text strings in log messages, based on  
a regular expression. The goal is to prevent sensitive information  
being logged.

Is there any easy way of doing this?

I have so far tried to write a simple implementation of the  
IObjectRenderer as  a small end to end test

namespace Log4netRegexpRenderer
{
     public class RegexpObjectRenderer : IObjectRenderer
     {
         /// <summary>
         /// Proceed to rendering for a given object.
         /// </summary>
         public string DoRender(RendererMap rendererMap, object obj)
         {
             return "Yeah, we're getting somehwere";
         }
     }
}

Then adding this to log4net.config:


     <renderer  
renderingClass="Log4netRegexpRenderer.RegexpObjectRenderer,  
Log4netRegexpRenderer" renderedClass="System.String, mscorlib" />

When I set the internal debug property in log4net to true, I can see  
that my assembly is pickedup and that there indeed is initialized an  
instance of my RegexpObjectRenderer.

However, it never calls DoRender in my custom object renderer. Is it  
possible to catch System.String/string by (mis)using the  
ObjectRenderer, or do I have to use custom objects? (Which works fine)

(I have no problems getting a custom renderer to work with my own  
custom classes, but no luck with System.String).

Suggestions?

Regards,

Lars