@@ -64,7 +64,7 @@ public void SupportsStylingWithProperties()
64
64
} ;
65
65
var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Hello<<_>> <<{ STYLE2 } >>{{{OutputProperties.PropertiesPropertyName}}}<<_>>", default ) ;
66
66
var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , MessageTemplate . Empty , PROPERTIES ) ) ;
67
- Assert . Equal ( [ $ "%cHello%c %c%o %c", STYLE1 , "" , STYLE2 , ( ( ScalarValue ) PROPERTIES [ 0 ] . Value ) . Value , "" ] , args ) ;
67
+ Assert . Equal ( [ $ "%cHello%c %c%d %c", STYLE1 , "" , STYLE2 , ( ( ScalarValue ) PROPERTIES [ 0 ] . Value ) . Value , "" ] , args ) ;
68
68
}
69
69
70
70
[ Fact ]
@@ -77,24 +77,61 @@ public void SupportsStylingWithSimpleMessage()
77
77
}
78
78
79
79
[ Fact ]
80
- public void SupportsStylingWithMessageContainingInterpolation ( )
80
+ public void SupportsStylingWithinSimpleMessageContainingStyle ( )
81
81
{
82
- var PLACE = "my tests" ;
83
- var MESSAGE = "and welcome to {Place}" ;
82
+ var MESSAGE = $ "and <<{ STYLE3 } >>welcome";
84
83
var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Hello<<_>> <<{ STYLE2 } >>{{{OutputProperties.MessagePropertyName}}}<<_>>", default ) ;
85
- var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , new [ ] {
86
- new LogEventProperty ( "Place" , new ScalarValue ( PLACE ) ) ,
87
- } ) ) ;
88
- Assert . Equal ( [ $ "%cHello%c %c{ MESSAGE . Replace ( "{Place}" , "%o" ) } %c", STYLE1 , "" , STYLE2 , PLACE , "" ] , args ) ;
84
+ var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , Array . Empty < LogEventProperty > ( ) ) ) ;
85
+ Assert . Equal ( [ $ "%cHello%c %c{ MESSAGE . Replace ( $ "<<{ STYLE3 } >>", "%c" ) } %c", STYLE1 , "" , STYLE2 , STYLE3 , "" ] , args ) ;
86
+ }
87
+
88
+ [ Theory ]
89
+ [ InlineData ( "short" , "%d" , ( short ) 42 ) ]
90
+ [ InlineData ( "int" , "%d" , ( int ) 42 ) ]
91
+ [ InlineData ( "long" , "%d" , ( long ) 42 ) ]
92
+ [ InlineData ( "ushort" , "%d" , ( ushort ) 42 ) ]
93
+ [ InlineData ( "uint" , "%d" , ( uint ) 42 ) ]
94
+ [ InlineData ( "ulong" , "%d" , ( ulong ) 42 ) ]
95
+ [ InlineData ( "byte" , "%d" , ( byte ) 42 ) ]
96
+ [ InlineData ( "sbyte" , "%d" , ( sbyte ) 42 ) ]
97
+ // [InlineData("decimal", "%f", (decimal)42m)] // Unsupported
98
+ [ InlineData ( "double" , "%f" , ( double ) 42m ) ]
99
+ [ InlineData ( "float" , "%f" , ( float ) 42m ) ]
100
+ [ InlineData ( "string" , "%s" , ( string ) "foo" ) ]
101
+ [ InlineData ( "char" , "%s" , ( char ) 'f' ) ]
102
+ public void SupportsStylingWithMessageContainingScalarStandardValues ( string propertyName , string template , object value )
103
+ {
104
+ var MESSAGE = $ "where the prop is {{{propertyName}}}";
105
+ var PROPERTIES = new [ ] {
106
+ new LogEventProperty ( propertyName , new ScalarValue ( value ) ) ,
107
+ } ;
108
+ var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Test {{{OutputProperties.MessagePropertyName}}} End<<_>>", default ) ;
109
+ var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , PROPERTIES ) ) ;
110
+ Assert . Equal ( [ $ "%cTest where the prop is { template } End%c", STYLE1 , ( ( ScalarValue ) PROPERTIES [ 0 ] . Value ) . Value , "" ] , args ) ;
89
111
}
90
112
91
113
[ Fact ]
92
- public void SupportsStylingWithinSimpleMessage ( )
114
+ public void SupportsStylingWithMessageContainingScalarDecimal ( )
93
115
{
94
- var MESSAGE = $ "and <<{ STYLE3 } >>welcome";
95
- var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Hello<<_>> <<{ STYLE2 } >>{{{OutputProperties.MessagePropertyName}}}<<_>>", default ) ;
96
- var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , Array . Empty < LogEventProperty > ( ) ) ) ;
97
- Assert . Equal ( [ $ "%cHello%c %c{ MESSAGE . Replace ( $ "<<{ STYLE3 } >>", "%c" ) } %c", STYLE1 , "" , STYLE2 , STYLE3 , "" ] , args ) ;
116
+ var MESSAGE = $ "where the prop is {{decimal}}";
117
+ var PROPERTIES = new [ ] {
118
+ new LogEventProperty ( "decimal" , new ScalarValue ( ( decimal ) 42m ) ) ,
119
+ } ;
120
+ var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Test {{{OutputProperties.MessagePropertyName}}} End<<_>>", default ) ;
121
+ var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , PROPERTIES ) ) ;
122
+ Assert . Equal ( [ $ "%cTest where the prop is %f End%c", STYLE1 , ( ( ScalarValue ) PROPERTIES [ 0 ] . Value ) . Value , "" ] , args ) ;
123
+ }
124
+
125
+ [ Fact ]
126
+ public void SupportsStylingWithMessageContainingScalarObject ( )
127
+ {
128
+ var MESSAGE = $ "where the prop is {{object}}";
129
+ var PROPERTIES = new [ ] {
130
+ new LogEventProperty ( "object" , new ScalarValue ( new { Hello = "world" } ) ) ,
131
+ } ;
132
+ var formatter = new OutputTemplateRenderer ( $ "<<{ STYLE1 } >>Test {{{OutputProperties.MessagePropertyName}}} End<<_>>", default ) ;
133
+ var args = formatter . Format ( new LogEvent ( DateTimeOffset . Now , LogEventLevel . Verbose , null , new MessageTemplateParser ( ) . Parse ( MESSAGE ) , PROPERTIES ) ) ;
134
+ Assert . Equal ( [ $ "%cTest where the prop is %c%o%c End%c", STYLE1 , "" , ( ( ScalarValue ) PROPERTIES [ 0 ] . Value ) . Value , STYLE1 , "" ] , args ) ;
98
135
}
99
136
100
137
[ Fact ]
0 commit comments