LogCallHandler parameter formatting

Apr 14, 2011 at 9:39 PM
Edited Apr 14, 2011 at 9:42 PM

When using policy injection with the LogCallHandler, how can I contro lthe formatting of the method parameters? The formatting for basic types seems to work ok, but when I have methods with things like List<string> types, things don't work so well.

For example, if the method signature is:

doSomething(List<string> listparam)   

and using the log formatting that looks like


Extended Properties: {dictionary({key} - {value}{newline})}

Then if I call doSomething(new List<String>{"a", "b"}) I get something like this in the log

Extended Properties: listparam - System.Collections.Generic.List`1[System.String]

Instead of something like

Extended Properties: listparam - {"a", "b"}

I assume that the formatter works by calling the ToString() of the parameter value, but I don't want to force code to pass in a subclassed List<string> that  overrides ToString() appropriately.

Is there a way get this done?


Dan Griffin


Apr 15, 2011 at 3:02 AM
Edited Apr 15, 2011 at 3:03 AM

Yes, it just calls the .ToString method.  If you don't want to create your own class inheriting from a List, the other way would be to create a custom log formatter.  It would merely copy much of the code of the TextFormatter class.  If you look at the source code, the only thing you'll need to modify in the code you copied from that class is the logic of the DictionaryTokenHandlerFactory method.   Basically, you need to modify this line of code:

handlers["value"] = GenericTextFormatter<KeyValuePair<string, object>>.CreateSimpleTokenHandler(kvp => kvp.Value.ToString());


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.

Apr 15, 2011 at 11:40 AM

Thank you Sarah! I will try that....