@@ -10,9 +10,8 @@ namespace Microsoft.Extensions.Diagnostics.Buffering;
10
10
/// <summary>
11
11
/// Represents a log record that has been serialized for purposes of buffering or similar.
12
12
/// </summary>
13
- #pragma warning disable CA1815 // Override equals and operator equals on value types
13
+ #pragma warning disable CA1815 // Override equals and operator equals on value types - not used for this struct, would be dead code
14
14
internal readonly struct SerializedLogRecord
15
- #pragma warning restore CA1815 // Override equals and operator equals on value types
16
15
{
17
16
/// <summary>
18
17
/// Initializes a new instance of the <see cref="SerializedLogRecord"/> struct.
@@ -41,16 +40,28 @@ public SerializedLogRecord(
41
40
serializedAttributes = new List < KeyValuePair < string , object ? > > ( attributes . Count ) ;
42
41
for ( int i = 0 ; i < attributes . Count ; i ++ )
43
42
{
43
+ string key = attributes [ i ] . Key ;
44
44
string value = attributes [ i ] . Value ? . ToString ( ) ?? string . Empty ;
45
- serializedAttributes . Add ( new KeyValuePair < string , object ? > ( attributes [ i ] . Key , value ) ) ;
45
+ serializedAttributes . Add ( new KeyValuePair < string , object ? > ( key , value ) ) ;
46
+
47
+ SizeInBytes += key . Length * sizeof ( char ) ;
46
48
SizeInBytes += value . Length * sizeof ( char ) ;
47
49
}
48
-
49
- Exception = exception ? . Message ;
50
50
}
51
51
52
52
Attributes = serializedAttributes ;
53
+
54
+ Exception = exception ? . Message ;
55
+ if ( Exception is not null )
56
+ {
57
+ SizeInBytes += Exception . Length * sizeof ( char ) ;
58
+ }
59
+
53
60
FormattedMessage = formattedMessage ;
61
+ if ( FormattedMessage is not null )
62
+ {
63
+ SizeInBytes += FormattedMessage . Length * sizeof ( char ) ;
64
+ }
54
65
}
55
66
56
67
/// <summary>
0 commit comments