Logging message contents

Component: NServiceBus | Nuget: NServiceBus (Version: 3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

When NServiceBus sends a message, it writes the result of the ToString() method of the message class to the log. By default, this writes the name of the message type only. To write the full message contents to the log, override the ToString() method of the relevant message class. Here's an example:

public class MessageToLog :
    public Guid EventId { get; set; }
    public DateTime? Time { get; set; }
    public TimeSpan Duration { get; set; }

    public override string ToString()
        return $"MyMessage: EventId={EventId}, Time={Time}, Duration={Duration}";
NServiceBus only makes these calls at a log threshold of DEBUG or lower.

Last modified