Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the log framework NLog send logs to messages

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "log framework NLog how to send the log to email", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "log framework NLog how to send logs to email" bar!

Background

NLog can output logs to different media, and e-mail is one of them, through which we can receive messages as soon as possible. Log messages are sent via email using the SMTP protocol. Works well with FallbackGroup Target to create a backup with multiple SMTP hosts.

Configuration syntax

Parameters.

General option

Name-destination name.

Layout option

Header-header. Overall Arrangement

Footer-footer. Overall Arrangement

Layout-the text to render. Layout is required. Default value: ${message} ${newline}. Same as body attribute.

Html- indicates whether to send the message as HTML instead of plain text. Boolean default value: false

AddNewLines- indicates whether to add new lines between log entries. Boolean type

ReplaceNewlineWithBrTagInHtml-indicates whether the newline character in the body should be changed to

Label. Boolean default value: false

Encoding-the encoding used to send e-mail. Encoding default value: UTF-8 message option

Subject-the subject of the message. Layout is required. Default: messages from NLog on ${machinename}

To-the recipient's email address, separated by a semicolon (for example, john@domain.com;jane@domain.com). Overall Arrangement. Starting with NLog 4. 0, this field is no longer needed, but To,BCC or CC should be defined, otherwise an exception will be thrown.

BCC-A BCC email address separated by a semicolon (e.g. john@domain.com;jane@domain.com). Overall Arrangement

Cc- CC email addresses separated by semicolons (for example, john@domain.com;jane@domain.com). Overall Arrangement

From-the email address of the sender (for example, joe@domain.com). Layout is required.

Body-same layout attribute. Message message body (repeated for each log message sent in a message). Layout default: ${message} ${newline}

Priority-message priority.

Use System.Net.Mail.MailPriority when using NLog without the NLog.MailKit package. Low,Normal,High .

When using the Nlog + NLog.MailKit version up to v3.1, the valid value is MimeKit.MessagePriority. NonUrgent,Normal,Urgent

NLog.MailKit v3.2 and above accept NonUrgent / Low,Normal,Urgent / High for backward compatibility with the MTP option

The user name used by smtpUserName- to connect to the SMTP server (used when SmtpAuthentication is set to basic). Overall Arrangement

EnableSsl- indicates whether SSL (secure Sockets layer) should be used when communicating with the SMTP server. Boolean default: False. Note: Port 465 is not available for SSL. See question 1226

SecureSocketOption- is only in NLog.Mailkit 2.1 +. Provides a way to specify SSL and / or TLS encryption. The default is StartTlsWhenAvailable. Options: none, automatic, SslOnConnect,StartTls and StartTlsWhenAvailable. If enableSsl is set to true, SslOnConnect will be used

The password used by smtpPassword- to authenticate against the SMTP server (used when SmtpAuthentication is set to basic). Overall Arrangement

SmtpAuthentication-SMTP authentication mode. Default value: none

Possible values:

Basic-basic-username and password.

None-No authentication.

Ntlm-NTLM authentication.

The SMTP server that smtpServer- uses to send. Layout is required.

SmtpPort-the port number that the SMTP server is listening on. The default integer value is 25. Note: SSL is not supported on port 465. See question 1226

UseSystemNetMailSettings- enforces the use of smtp configuration from system.net/mailSettings. Boolean default value: False

Timeout-indicates that the SMTP client timed out in milliseconds. Integer default value: 10000 (10 seconds)

PickupDirectoryLocation- gets or sets the folder that the application uses to hold messages to be processed by the local SMTP server (introduced in NLog 4.2).

DeliveryMethod- specifies how outgoing e-mail will be handled (introduced in NLog 4.2). Default value: possible values for the network:

Network-email is sent to the SMTP server over the network.

PickupDirectoryFromIis- e-mail messages are copied to the extraction directory used by the local Internet Information Service (IIS) for delivery.

SpecifiedPickupDirectory- copies the e-mail to the directory specified by the PickupDirectoryLocation property for delivery by external applications.

SkipCertificateValidation- applies only to NLog.MailKit. Introduce-skip SSL authentication check in NLog.MailKit 1.1

Mode of realization

1. Vs add reference NLog.MailKit

2. Configure nlog

...

3. Config configure mailbox information

4. Configure log parameters

Finally, you can receive the log mail.

Thank you for your reading, the above is the "log framework NLog how to send logs to mail" content, after the study of this article, I believe you on the log framework NLog how to send logs to mail this problem has a deeper understanding, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report