squ*_*are 8 c# nlog html-email
下面的配置是我的 nlog 设置,这个设置发送邮件是可以的。
<target name="mail" xsi:type="Mail"
smtpServer="SMTP SERVER"
smtpPort="25"
smtpAuthentication="None"
enableSsl="false"
from="email address"
to="email address"
html="true"
encoding="UTF-8"
addNewLines="true"
replaceNewlineWithBrTagInHtml ="true"
subject="SYSTEM MESSAGE?${machinename} ? ${shortdate} ${time} create ${level} message "
header="========================================================================="
body="${newline}
time?${longdate} ${newline}${newline}
Log level?${level:uppercase=true} ${newline}${newline}
Logger?${logger} ${newline}${newline}
Source?${callsite:className=true} ${newline}${newline}
Exception?${exception:format=type} ${newline}${newline}
Error message?${message} ${newline}${newline}"
footer="========================================================================="
/>
</targets>
<rules>
<logger name="*" minlevel="Fatal" writeTo="mail" />
</rules>
Run Code Online (Sandbox Code Playgroud)
但我想发送彩色邮件。如何设置configure?
对于电子邮件中的颜色等标记,您需要 html 邮件和 CSS 样式。
例如这个html:
<body>
<b style="color:red">Bold and red text</b>
</body>
Run Code Online (Sandbox Code Playgroud)
您需要将html邮件目标上的选项设置为,true并且在 nlog.config 中您需要对 html 进行 XML 编码,因此结果是:
<target name="mail" xsi:type="Mail"
html="true"
...
body="<body>
<b style="color:red">Bold and red text</b>
</body>"
/>
Run Code Online (Sandbox Code Playgroud)
请注意,并非所有电子邮件客户端都支持所有 CSS。请参阅电子邮件客户端的 CSS 支持指南