diff --git a/QuickFIXn/Logger/FileLogger.cs b/QuickFIXn/Logger/FileLogger.cs index 017c99e16..000a87f2f 100644 --- a/QuickFIXn/Logger/FileLogger.cs +++ b/QuickFIXn/Logger/FileLogger.cs @@ -87,10 +87,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None; - public IDisposable? BeginScope(TState state) where TState : notnull - { - throw new NotImplementedException(); - } + public IDisposable? BeginScope(TState state) where TState : notnull => default!; public void Dispose() { diff --git a/QuickFIXn/Session.cs b/QuickFIXn/Session.cs index f61c007aa..f8156fea1 100755 --- a/QuickFIXn/Session.cs +++ b/QuickFIXn/Session.cs @@ -349,14 +349,22 @@ public virtual bool Send(Message message) /// Sends a message /// /// + /// /// - public bool Send(string message) + public bool Send(string message, string messageType) { lock (_sync) { if (_responder is null) return false; - Log.Log(LogLevel.Information, LogEventIds.OutgoingMessage, "{Message}", message); + using (Log.BeginScope(new Dictionary + { + {"MessageType", messageType} + })) + { + Log.Log(LogLevel.Information, LogEventIds.OutgoingMessage, "{Message}", message); + } + return _responder.Send(message); } } @@ -513,7 +521,21 @@ public void Next(string msgStr) /// private void NextMessage(string msgStr) { - Log.Log(LogLevel.Information, LogEventIds.IncomingMessage, "{Message}", msgStr); + try + { + var messageType = Message.IdentifyType(msgStr); + using (Log.BeginScope(new Dictionary + { + {"MessageType", messageType.Value} + })) + { + Log.Log(LogLevel.Information, LogEventIds.IncomingMessage, "{Message}", msgStr); + } + } + catch (Exception) + { + Log.Log(LogLevel.Information, LogEventIds.IncomingMessage, "{Message}", msgStr); + } MessageBuilder msgBuilder = new MessageBuilder( msgStr, @@ -789,7 +811,7 @@ protected void NextResendRequest(Message resendReq) { GenerateSequenceReset(resendReq, begin, msgSeqNum); } - Send(msg.ConstructString()); + Send(msg.ConstructString(), msg.Header.GetString(Tags.MsgType)); begin = 0; } current = msgSeqNum + 1; @@ -1572,7 +1594,7 @@ protected bool SendRaw(Message message, SeqNumType seqNum) string messageString = message.ConstructString(); if (0 == seqNum) Persist(message, messageString); - return Send(messageString); + return Send(messageString, message.Header.GetString(Tags.MsgType)); } }