File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
src/Serilog.Extensions.Logging/Extensions/Logging Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 1313// limitations under the License.
1414
1515using System ;
16+ using System . Linq ;
1617using Microsoft . Extensions . Logging ;
18+ using Microsoft . Extensions . Logging . Internal ;
1719using Serilog . Core ;
1820using Serilog . Events ;
21+ using Serilog . Parsing ;
1922
2023namespace Serilog . Extensions . Logging
2124{
@@ -39,17 +42,31 @@ sourceContextProperty is ScalarValue sourceContextValue &&
3942 categoryName = sourceContext ;
4043 }
4144
45+ // Allocates like mad, but first make it work, then make it work fast ;-)
46+ var flv = new FormattedLogValues (
47+ logEvent . MessageTemplate . Text ,
48+ logEvent . MessageTemplate . Tokens
49+ . OfType < PropertyToken > ( )
50+ . Select ( p =>
51+ {
52+ if ( ! logEvent . Properties . TryGetValue ( p . PropertyName , out var value ) )
53+ return null ;
54+ if ( value is ScalarValue sv )
55+ return sv . Value ;
56+ return value ;
57+ } )
58+ . ToArray ( ) ) ;
59+
4260 foreach ( var provider in _providers . Providers )
4361 {
4462 var logger = provider . CreateLogger ( categoryName ) ;
4563
46-
4764 logger . Log (
4865 LevelMapping . ToExtensionsLevel ( logEvent . Level ) ,
4966 default ( EventId ) ,
50- logEvent ,
67+ flv ,
5168 logEvent . Exception ,
52- ( s , ex ) => s . RenderMessage ( ) ) ;
69+ ( s , e ) => s . ToString ( ) ) ;
5370 }
5471 }
5572
You can’t perform that action at this time.
0 commit comments