Acropolis.Foundation.EventSourcing.Logging.EventHandlerRecord.ToBson C# (CSharp) Метод

ToBson() публичный статический Метод

To Bson
public static ToBson ( EventHandlerRecord record ) : BsonDocument
record EventHandlerRecord
Результат BsonDocument
        public static BsonDocument ToBson(EventHandlerRecord record)
        {
            return new BsonDocument
            {
                { "HandlerId", record.HandlerId ?? "" },
                { "EventId", record.EventId ?? "" },
                { "CommandId", record.CommandId ?? "" },
                { "TypeName", record.TypeName ?? "" },
                { "StartedDate", record.StartedDate },
                { "EndedDate", record.EndedDate },
                { "ErrorMessage", record.ErrorMessage ?? "" },
                { "ErrorStackTrace", record.ErrorStackTrace ?? "" },
            };
        }

Usage Example

Пример #1
0
        public void LogEventHandler(EventHandlerRecord record)
        {
            try
            {
                var handlerDoc = EventHandlerRecord.ToBson(record);

                var query = Query.And(
                    Query.EQ("_id", record.CommandId),
                    Query.EQ("Events.Event.Metadata.EventId", record.EventId)
                    );

                var update = Update.Push("Events.$.Handlers", handlerDoc);
                Write.Logs.Update(query, update);
            }
            catch (Exception e)
            {
                // Catch all errors because logging should not throw errors if unsuccessful
            }
        }
EventHandlerRecord