2121
2222using System ;
2323using System . Linq ;
24+ using System . Web . Script . Serialization ;
2425
2526using Castle . DynamicProxy ;
2627
2728using Common . Logging ;
2829
30+ using Patterns . Collections . Strategies ;
31+
2932namespace Patterns . Logging
3033{
3134 /// <summary>
@@ -42,6 +45,14 @@ public class LoggingInterceptor : IInterceptor
4245 private readonly LoggingConfig _config ;
4346 private readonly Func < Type , ILog > _logFactory ;
4447
48+ private static readonly FuncStrategies < Type , object , object > _displayStrategies
49+ = new FuncStrategies < Type , object , object >
50+ {
51+ { typeof ( string ) , value => string . Format ( _stringDisplayFormat , value ) }
52+ } ;
53+
54+ private static readonly JavaScriptSerializer _jsonSerializer = new JavaScriptSerializer ( ) ;
55+
4556 /// <summary>
4657 /// Initializes a new instance of the <see cref="LoggingInterceptor" /> class.
4758 /// </summary>
@@ -92,7 +103,11 @@ private static string GetMethodArguments(IInvocation invocation)
92103 private static object ConvertValueForDisplay ( object value )
93104 {
94105 if ( value == null ) return _nullArgument ;
95- return value is string ? string . Format ( _stringDisplayFormat , value ) : value ;
106+
107+ Type valueType = value . GetType ( ) ;
108+ object newValue = _displayStrategies . Execute ( valueType , value ) ;
109+
110+ return newValue ?? _jsonSerializer . Serialize ( value ) ;
96111 }
97112 }
98113}
0 commit comments