File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
src/Serilog.Sinks.ElmahIO/Sinks/ElmahIo Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 11using Elmah . Io . Client ;
2+ using Serilog . Events ;
23using System . Collections . Generic ;
34
45#pragma warning disable IDE0130 // Namespace does not match folder structure
@@ -9,13 +10,23 @@ internal static class KeyValuePairExtensions
910 {
1011 internal static Item ToItem < TKey , TValue > ( this KeyValuePair < TKey , TValue > keyValuePair )
1112 {
12- return new Item ( Trim ( keyValuePair . Key ? . ToString ( ) ) , Trim ( keyValuePair . Value ? . ToString ( ) ) ) ;
13+ return new Item ( RawValue ( keyValuePair . Key ) , RawValue ( keyValuePair . Value ) ) ;
1314 }
1415
15- private static string Trim ( string s )
16+ private static string RawValue ( object obj )
1617 {
17- if ( string . IsNullOrWhiteSpace ( s ) ) return null ;
18- return s . TrimStart ( '\" ' ) . TrimEnd ( '\" ' ) ;
18+ if ( obj == null ) return null ;
19+
20+ // Handling of ScalarValue from Serilog
21+ if ( obj is ScalarValue scalar )
22+ {
23+ return scalar . Value ? . ToString ( ) ;
24+ }
25+
26+ // For other types, use ToString and treat whitespace as null
27+ var result = obj . ToString ( ) ;
28+
29+ return string . IsNullOrWhiteSpace ( result ) ? null : result ;
1930 }
2031 }
2132}
You can’t perform that action at this time.
0 commit comments