@@ -383,9 +383,7 @@ private MetadataDictionary GetMetadata(LogEventInfo e)
383
383
continue ;
384
384
385
385
var propertyValue = prop . Value ;
386
- if ( propertyValue is null or IConvertible || propertyValue . GetType ( ) . IsValueType )
387
- Populate ( metadata , propertyName , propertyValue ) ;
388
- else
386
+ if ( ! TryPopulateWhenSafe ( metadata , propertyName , propertyValue ) )
389
387
{
390
388
templateParameters ??= e . MessageTemplateParameters ;
391
389
var value = AllowSerializePropertyValue ( propertyName , templateParameters ) ? propertyValue : propertyValue . ToString ( ) ;
@@ -402,7 +400,10 @@ private MetadataDictionary GetMetadata(LogEventInfo e)
402
400
continue ;
403
401
404
402
var propertyValue = MappedDiagnosticsLogicalContext . GetObject ( key ) ;
405
- Populate ( metadata , key , propertyValue ) ;
403
+ if ( ! TryPopulateWhenSafe ( metadata , key , propertyValue ) )
404
+ {
405
+ Populate ( metadata , key , propertyValue . ToString ( ) ) ;
406
+ }
406
407
}
407
408
}
408
409
@@ -722,6 +723,19 @@ private static long GetSysLogSeverity(LogLevel logLevel)
722
723
return 2 ; // LogLevel.Fatal
723
724
}
724
725
726
+ private static bool TryPopulateWhenSafe ( IDictionary < string , object > propertyBag , string key , object value )
727
+ {
728
+ if ( value is null or IConvertible || value . GetType ( ) . IsValueType )
729
+ {
730
+ if ( value is Enum )
731
+ value = value . ToString ( ) ;
732
+ Populate ( propertyBag , key , value ) ;
733
+ return true ;
734
+ }
735
+
736
+ return false ;
737
+ }
738
+
725
739
private static void Populate ( IDictionary < string , object > propertyBag , string key , object value )
726
740
{
727
741
if ( string . IsNullOrEmpty ( key ) )
0 commit comments