The Email target sends an email for each message. It is useful when critical issues occur. Buffering may also make sense for this type of target.
It has these properties that can be configured:
- Name - Defaults to EmailTarget
- LoggingMode - Defines which mode to use for the target; Synchronous, Buffered, or Asynchronous. The default is Synchronous.
- MessageFormat - What to output in the log. See the Message Format topic for more information.
- DateFormat - The date format for the %LogTime% variable in the MessageFormat. See the Date Format topic for more information.
- MinimumLevel - The minimum logging level to log a message.
- AssemblyNameFilter - If specified, only log for a specific assembly name. See the Filtering topic.
- NamespaceFilter - If specified, only log for a specific namespace. See the Filtering topic.
- ClassNameFilter - If specified, only log for a specific class name. See the Filtering topic.
- MethodNameFilter - If specified, only log for a specific method name. See the Filtering topic.
- ThreadNameFilter - If specified, logging will only occur for the thread id or thread name specified. See the Filtering topic.
- UserNameFilter - If specified, logging will only occur for the specific user name. See the Filtering topic.
- MachineNameFilter - If specified, logging will only occur for the specific machine name. See the Filtering topic.
- BufferSize - When a logging target has a Mode of Buffered, this is how often messages are committed. See the Buffered Logging topic.
- FromEmail - The email address of the sender
- ToEmail - A comma delimited list of recipients
- Bcc - A comma delimited list of blind carbon copy recipients
- Cc - A comma delimited list of carbon copy recipients
- Subject - The subject of the email. Defaults to: Kellerman Logger
- IsBodyHtml - True if the body is html. Defaults to false.
- SmtpServer - The name or IP address of the SMTP server to send the mail through
- SmtpPort - The port to send the email through. Defaults to 25
- UserName - he user name for the email account
- Password - The password for the email account
- UseSsl - If true, use SSL when connecting to the SMTP Server. Defaults to false.
//Example runtime configuration, can also use log.config, app.config, or web.config
Log.ResetConfiguration();
// Initialize email target
EmailTarget target = new EmailTarget();
target.SmtpServer = "mail.example.com";
target.SmtpPort = 25;
target.FromEmail = "testemail@example.com";
target.ToEmail = "testemail2@example.com";
target.Bcc = "";
target.Subject = "Logging message";
target.IsBodyHtml = true;
target.UserName = "testemail@example.com";
target.Password = "secret";
Log.Config.Targets.Add(target);
Log.Debug("This is a test");