SmtpLogNewEntry Event
Occurs when an entry is written into the log file (or into the memory buffer if Smtp.Log.MemoryLog is true).

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public event LogNewEntryEventHandler LogNewEntry

Value

Type: MailBeeLogNewEntryEventHandler
Remarks

This event is raised only if logging is turned on (Enabled is true).

MailBee raises this event BEFORE adding the entry into the the log. Since many properties of NewEntry object are editable, the developer can change the data MailBee will put into the log or even cancel logging the current entry at all. This may be useful the developer wishes to log only those entires which meet certain criteria.

Note Note
Entries added by the developer (through WriteLine(String) method call) do not cause this event to be raised. Thus, it's safe to add user-defined log entries even in the LogNewEntry event handler itself. This does not cause endless recursion which would otherwise occur if WriteLine(String) method called in LogNewEntry event handler raised this event again.
Examples
This sample enables logging the SMTP session into a file, and logs only those entries which indicate any data traffic between the client (MailBee) and the server. Other entries are discarded, and user-defined log entry is added instead. The sample is written for a console application.
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    // LogNewEntry event handler.
    private static void OnLogNewEntry(object sender, LogNewEntryEventArgs e)
    {
        if ( !(e.NewEntry.MessageType == LogMessageType.Recv ||
            e.NewEntry.MessageType == LogMessageType.Send) )
        {
            // Do not add this entry if it does not indicate any data transfer,
            // and put our own message instead.
            e.NewEntry.AddThisEntry = false;
            ((Smtp)sender).Log.WriteLine("UNWANTED MESSAGE REMOVED");

            // Note: we could produce similar results just by writing new values 
            // into MessageText and MessageComment properties of the original entry.
            // The code above uses Log.WriteLine method just to show how to add new 
            // entries in the event handler itself. You may comment 2 code lines above 
            // and uncomment 2 code lines below to use the alternate approach.
            // 
            // e.NewEntry.MessageText = "UNWANTED MESSAGE REMOVED";
            // e.NewEntry.MessageComment = string.Empty;
        }
    }

    // The actual code.
    static void Main(string[] args)
    {
        Smtp mailer = new Smtp();

        mailer.SmtpServers.Add("smtp.domain.com");

        // Enable logging the SMTP session into a file.
        mailer.Log.Enabled = true;
        mailer.Log.Filename = @"C:\Temp\log.txt";
        mailer.Log.Format = LogFormatOptions.AddContextInfo;
        mailer.Log.Clear();

        // Subscribe to the LogNewEntry event.
        mailer.LogNewEntry += new LogNewEntryEventHandler(OnLogNewEntry);

        // Do something which would produce some network traffic.
        mailer.Connect();
        mailer.Hello();
        mailer.Disconnect();
    }
}
See Also