I have two properties of Type IDictionary<string, Object>

  • ConfigProperties and CustomProperties

Both have the same values set to them. But one is set through a constructor and the other is from a method signature with help of a static method.

in likewise manner:

Static Method returning IDictionary<string, object> and is later passed on LogMessageEvent.

public void LogMessageEvent(IDictionary<string, object> dictionary, string eventMessage, IReadOnlyCollection<Exception> exceptions, Guid messageId, Guid sessionId, LogMessageType logMessageType, ErrorLevel errorLevel)
        {    
            LogEntity m = new LogEntity(messageId, sessionId, EntityType.Message, logMessageType, errorLevel, dictionary);

                m.Description = eventMessage;
                m.CustomProperties.Add("Configuration", dictionary);
...

Lastly the Constructor way.

public LogEntity(Guid id, Guid relatedId, EntityType entityType, LogMessageType logMessageType, ErrorLevel errorLevel, IDictionary<string,object> configProperties) : base(id, relatedId, entityType)
        {
            ConfigProperties = configProperties,
    ...
        }

Later whenever i print these on the EventViewer I get two different results.

Alternative A

System.Diagnostics.EventLog.WriteEntry("SendAsync", "ConfigProperties: \n " + string.Join(Environment.NewLine, logMessage.ConfigProperties), EventLogEntryType.Error);

Outputs

ConfigProperties: 
 [Url, hej]
[SpecificUrlParameters, {
  "HoursSinceUpdated": "-72"
}]
[Parameters, {
  "Authorization": "LoginTokenProperty"
}]
[HmacArgs, {}]
[StaticPostMessage, ]
[Encryption, tls12]
[LookForCertificate, false] ...

Alternative B CustomProperties - IDictionary<string, Object>

System.Diagnostics.EventLog.WriteEntry("SendAsync", "CustomProps: item:  " + string.Join(Environment.NewLine, logMessage.CustomProperties["Configuration"]), EventLogEntryType.Error);

Outputs

CustomProps: item:  System.Collections.Generic.Dictionary`2[System.String,System.Object]
0

There are 0 best solutions below