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 13
13
// limitations under the License.
14
14
15
15
using System ;
16
+ using System . Linq ;
16
17
using Microsoft . Extensions . Logging ;
18
+ using Microsoft . Extensions . Logging . Internal ;
17
19
using Serilog . Core ;
18
20
using Serilog . Events ;
21
+ using Serilog . Parsing ;
19
22
20
23
namespace Serilog . Extensions . Logging
21
24
{
@@ -39,17 +42,31 @@ sourceContextProperty is ScalarValue sourceContextValue &&
39
42
categoryName = sourceContext ;
40
43
}
41
44
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
+
42
60
foreach ( var provider in _providers . Providers )
43
61
{
44
62
var logger = provider . CreateLogger ( categoryName ) ;
45
63
46
-
47
64
logger . Log (
48
65
LevelMapping . ToExtensionsLevel ( logEvent . Level ) ,
49
66
default ( EventId ) ,
50
- logEvent ,
67
+ flv ,
51
68
logEvent . Exception ,
52
- ( s , ex ) => s . RenderMessage ( ) ) ;
69
+ ( s , e ) => s . ToString ( ) ) ;
53
70
}
54
71
}
55
72
You can’t perform that action at this time.
0 commit comments