Protocol Logger Class
A default protocol logger for logging the communication between a client and server.
Definition
Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public class ProtocolLogger : IProtocolLogger,
IDisposable- Inheritance
- Object ProtocolLogger
- Implements
- IProtocolLogger, IDisposable
Remarks
A default protocol logger for logging the communication between a client and server.
Example
C#
public static void SendMessage (MimeMessage message)
{
using (var client = new SmtpClient (new ProtocolLogger ("smtp.log"))) {
client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
client.Send (message);
client.Disconnect (true);
}
// Example log:
//
// Connected to smtps://smtp.gmail.com:465/
// S: 220 smtp.gmail.com ESMTP w81sm22057166qkg.43 - gsmtp
// C: EHLO [192.168.1.220]
// S: 250-smtp.gmail.com at your service, [192.168.1.220]
// S: 250-SIZE 35882577
// S: 250-8BITMIME
// S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
// S: 250-ENHANCEDSTATUSCODES
// S: 250-PIPELINING
// S: 250-CHUNKING
// S: 250 SMTPUTF8
// C: AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk
// S: 235 2.7.0 Accepted
// C: MAIL FROM:<from.addr@gmail.com>
// C: RCPT TO:<to.addr@gmail.com>
// S: 250 2.1.0 OK w81sm22057166qkg.43 - gsmtp
// S: 250 2.1.5 OK w81sm22057166qkg.43 - gsmtp
// C: DATA
// S: 354 Go ahead w81sm22057166qkg.43 - gsmtp
// C: From: "LastName, FirstName" <from.addr@gmail.com>
// C: Date: Thu, 27 Dec 2018 10:55:18 -0500
// C: Subject: This is a test message
// C: Message-Id: <C7GVXWE3C6U4.7ZQ0K9OUHTDP1@MADUNLA-SP4.northamerica.corp.microsoft.com>
// C: To: "LastName, FirstName" <to.addr@gmail.com>
// C: MIME-Version: 1.0
// C: Content-Type: multipart/alternative; boundary="=-CToJI+AD2gS6z+fFlzDvhg=="
// C:
// C: --=-CToJI+AD2gS6z+fFlzDvhg==
// C: Content-Type: text/plain; charset=utf-8
// C: Content-Transfer-Encoding: quoted-printable
// C:
// C: This is the text/plain message body.
// C: --=-CToJI+AD2gS6z+fFlzDvhg==
// C: Content-Type: text/html; charset=utf-8
// C: Content-Transfer-Encoding: quoted-printable
// C:
// C: <html><body><center>This is the <b>text/html</b> message body.</center></body></html>
// C: --=-CToJI+AD2gS6z+fFlzDvhg==--
// C:
// C: .
// S: 250 2.0.0 OK 1545926120 w81sm22057166qkg.43 - gsmtp
// C: QUIT
// S: 221 2.0.0 closing connection w81sm22057166qkg.43 - gsmtp
}
Constructors
| ProtocolLogger(Stream, Boolean) | Initializes a new instance of the ProtocolLogger class. |
| ProtocolLogger(String, Boolean) | Initializes a new instance of the ProtocolLogger class. |
Properties
| AuthenticationSecretDetector | Get or set the authentication secret detector. |
| ClientPrefix | Get or set the client prefix to use when logging client messages. |
| DefaultClientPrefix | Get or set the default client prefix to use when creating new ProtocolLogger instances. |
| DefaultServerPrefix | Get or set the default server prefix to use when creating new ProtocolLogger instances. |
| LogTimestamps | Get or set whether timestamps should be logged. |
| RedactSecrets | Get or set whether or not authentication secrets should be redacted. |
| ServerPrefix | Get or set the server prefix to use when logging server messages. |
| Stream | Get the log stream. |
| TimestampFormat | Get or set the date and time serialization format that should be used when logging timestamps. |
Methods
| Dispose | Releases all resource used by the ProtocolLogger object. |
| Dispose(Boolean) | Releases the unmanaged resources used by the ProtocolLogger and optionally releases the managed resources. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Finalize |
Releases unmanaged resources and performs other cleanup operations before the ProtocolLogger
is reclaimed by garbage collection.
(Overrides ObjectFinalize) |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| LogClient | Logs a sequence of bytes sent by the client. |
| LogConnect | Logs a connection to the specified URI. |
| LogServer | Logs a sequence of bytes sent by the server. |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |