Logger Class |
Namespace: MailBee
The Logger type exposes the following members.
Name | Description | |
---|---|---|
Clear |
Clears the log contents if logging is enabled.
| |
ClearAsync |
async/await version of Clear.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetMemoryLog |
Returns the string containing the memory log contents.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
WriteLine |
Adds a new log entry containing user-defined message into the log.
| |
WriteLineAsync |
async/await version of WriteLine(String).
|
Name | Description | |
---|---|---|
DateTimeFormatFull |
Gets or sets the format of full datetime string.
| |
DateTimeFormatTimeOnly |
Gets or sets the format of time-only string.
| |
DisableOnException |
Gets or sets whether the logging should be automatically disabled instead of throwing exception when logging error occurs.
| |
Enabled |
Gets or sets whether the logging into a file or memory buffer is enabled.
| |
FileEncoding |
Gets or sets Encoding to be used when writing into
the log file.
| |
Filename |
Gets or sets the log file name.
| |
Format |
Gets or sets flags which specify formatting of log entries placed into the log.
| |
HidePasswords |
Gets or sets whether the actual password data may appear in the log or not.
| |
KeepLogFileOpen |
Gets or sets whether the log file must be kept open during MailBee session.
| |
LogDnsQueryBody |
Gets or sets whether DNS MX lookup query binary data must be added into the log.
| |
MaxSize |
Gets or sets the maximum allowed length (in characters) of the file or memory log.
| |
MemoryLog |
Gets or sets whether the logging must be performed into a log file or into a memory buffer.
| |
OldFilename |
Gets or sets the name of a backup file the log must be renamed into when its size
exceeds the maximum allowed limit.
| |
SyncRoot |
Gets or sets the object to be used for synchronized access to the log file.
|
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.
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();