Logger Class
Provides logging facilities for MailBee components such as Smtp, Pop3, and Imap.
Inheritance Hierarchy
SystemObject
  MailBeeLogger

Namespace: MailBee
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public class Logger

The Logger type exposes the following members.

Methods
  NameDescription
Public methodClear
Clears the log contents if logging is enabled.
Public methodClearAsync
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetMemoryLog
Returns the string containing the memory log contents.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleWriteLine
Adds a new log entry containing user-defined message into the log.
Public methodWriteLineAsync
async/await version of WriteLine(String).
Top
Properties
  NameDescription
Public propertyDateTimeFormatFull
Gets or sets the format of full datetime string.
Public propertyDateTimeFormatTimeOnly
Gets or sets the format of time-only string.
Public propertyDisableOnException
Gets or sets whether the logging should be automatically disabled instead of throwing exception when logging error occurs.
Public propertyEnabled
Gets or sets whether the logging into a file or memory buffer is enabled.
Public propertyFileEncoding
Gets or sets Encoding to be used when writing into the log file.
Public propertyFilename
Gets or sets the log file name.
Public propertyFormat
Gets or sets flags which specify formatting of log entries placed into the log.
Public propertyHidePasswords
Gets or sets whether the actual password data may appear in the log or not.
Public propertyKeepLogFileOpen
Gets or sets whether the log file must be kept open during MailBee session.
Public propertyLogDnsQueryBody
Gets or sets whether DNS MX lookup query binary data must be added into the log.
Public propertyMaxSize
Gets or sets the maximum allowed length (in characters) of the file or memory log.
Public propertyMemoryLog
Gets or sets whether the logging must be performed into a log file or into a memory buffer.
Public propertyOldFilename
Gets or sets the name of a backup file the log must be renamed into when its size exceeds the maximum allowed limit.
Public propertySyncRoot
Gets or sets the object to be used for synchronized access to the log file.
Top
Remarks

The logging is the first tool to use for troubleshooting. If you encounter any problems with Smtp, Pop3 or Imap component, please enable the logging first, and try again.

The log provides a lot of useful and detailed information on how MailBee communicates with mail or DNS servers. The logs keeps track of all occurred network connection and protocol errors as well.

Logger class also supports logging into memory buffer instead of a file (useful for those ASP.NET applications which have no permissions to write to disk).

To prevent unlimited growth of the log file/memory buffer, the maximum size of the log can be restricted to certain value (see MaxSize property).

The developer has control of adding log messages. Each time the log entry is to be added into the log, MailBee components raise LogNewEntry event (see Smtp.LogNewEntry, Pop3.LogNewEntry, and Imap.LogNewEntry). Also, the developer can explicitly put new entries into the log using WriteLine(String) method.

Examples
This sample enables logging POP3 session into C:\Temp\pop3_log.txt file. The maximum size of the log file is restricted to 4 Kbytes. If the log file is going to exceed this size, it's renamed into C:\Temp\pop3_log-bak.txt, and new C:\Temp\pop3_log.txt log is started.
Note Note
If C:\Temp\pop3_log.txt gets full again, it's again renamed to C:\Temp\pop3_log-bak.txt (old C:\Temp\pop3_log-bak.txt contents will be lost). Thus, the log will always reflect the latest activity, however, older data may be lost.
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

// The actual code (put it into a method of your class)
Pop3 pop = new Pop3();

// Set logging parameters.
pop.Log.Enabled = true;
pop.Log.Filename = @"C:\Temp\pop3_log.txt";
pop.Log.MaxSize = 4096;
pop.Log.OldFilename = @"C:\Temp\pop3_log-bak.txt";

// Download all message headers to produce some log messages.
pop.Connect("mail.domain.com");
pop.Login("user@domain.com", "password");
MailMessageCollection msgs = pop.DownloadMessageHeaders();
pop.Disconnect();
See Also