Logging Example

The following example demonstrates creating an IMAP session log.

There are two basic ways of logging. One is to actually create a text file. The following example creates a text file log at c:\imap.log. If you do not have write permissions to create a file, you can always keep a log in memory. The following example also demonstrates keeping an in-memory log.

[C#]

IMAP4 imap = new IMAP4( "127.0.0.1" );
imap.Logger = new IMAPLog();

//if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\\imap.log";

//if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = true;

imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();

//list all of the folders
MailFolderCollection mfc = imap.FolderList();
Console.WriteLine( mfc.ToString() );

//write out the log
Console.WriteLine( imap.Logger.ToString() );

imap.Disconnect();

Console.WriteLine( "Done" );
Console.ReadLine();

 

[VB.NET]

Dim imap As New IMAP4("127.0.0.1")
imap.Logger = New IMAPLog()

'if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\imap.log"

'if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = True

imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()

'list all of the folders
Dim mfc As MailFolderCollection = imap.FolderList()
Console.WriteLine(mfc.ToString())

'write out the log
Console.WriteLine(imap.Logger.ToString())

imap.Disconnect()

Console.WriteLine("Done")
Console.ReadLine()