The delegate used for event handling.
This code example demonstrates how you could use the WriteLogEntry event to record log entries to a Sql server database.
[C#]
static void Main(string[] args)
{
IMAP4 imap = new IMAP4( "127.0.0.1" );
//create a log
imap.Logger = new IMAPLog();
//record the entries
imap.Logger.WriteLogEntry += new WriteLogEntryEventHandler( OnWriteEntry );
imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();
//list all of the folders
MailFolderCollection mfc = imap.FolderList();
Console.WriteLine( mfc.ToString() );
imap.Disconnect();
Console.WriteLine( "Done" );
Console.ReadLine();
}
private static void OnWriteEntry( object sender, WriteLogEntryEventArgs e )
{
//a method used for saving log entries to sql server
RecordToSqlServer( e.LogEntry );
}
private static void RecordToSqlServer( string entry )
{
//normally this method would be used for saving entries to an enterprise sql server.
//for demonstrations purposes, just write out the entry to the console
Console.Write( entry );
}
[VB.NET]
Public Overloads Shared Sub Main()
Dim imap As New IMAP4("127.0.0.1")
'create a log
imap.Logger = New IMAPLog()
'record the entries
AddHandler imap.Logger.WriteLogEntry, AddressOf OnWriteEntry
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())
imap.Disconnect()
Console.WriteLine("Done")
Console.ReadLine()
End Sub 'Main
Private Shared Sub OnWriteEntry(sender As Object, e As WriteLogEntryEventArgs)
'a method used for saving log entries to sql server
RecordToSqlServer(e.LogEntry)
End Sub
Private Shared Sub RecordToSqlServer(entry As String)
'normally this method would be used for saving entries to an enterprise sql server.
'for demonstrations purposes, just write out the entry to the console
Console.Write(entry)
End Sub
Namespace: aspNetIMAP
Assembly: aspNetIMAP (in aspNetIMAP.dll)