Вопрос

i have NLog configured to log error to mail target using corporate smtp server.

    <target name="email" xsi:type="Mail"
        from="aaa@aaa.cz"
        to="bbb@bbb.cz"
        subject="KIT - ${logger}"
        body="${message} ${exception:format=tostring}"
        smtpServer="ccc.ddd.cz"
        smtpPort="25"
        smtpUserName="abc"
        smtpPassword="abc" />

Everything works fine untill smtp server is down. I would like to somehow configure to use secondary smtp server when primary smtp server is not available - kind of SMTP failover.

Any ideas how to configure it in NLog? Is it possible to achieve this with NLog?

Это было полезно?

Решение

From the NLog FallbackGroup documentation on GitHub:

<targets>
  <target xsi:type="FallbackGroup" name="String" returnToFirstOnSuccess="Boolean">
    <target xsi:type="wrappedTargetType" ... />
    <target xsi:type="wrappedTargetType" ... />
    ...
    <target xsi:type="wrappedTargetType" ... />
  </target>
</targets>

List your targets in the order you wish NLog to attempt to use them. Don't forget to set the name="String" (in your case "email") and the returnToFirstOnSuccess="Boolean", usually "true" but maybe not for you, depending on why you had to failover/fallback. If it is usually just a transient problem, switching back to the primary makes sense. If it is usually because the primary server goes down for extended periods, you may want to set it to false so that a successful log using the secondary server doesn't make NLog switch back to the primary each time since it will just end up doing the fallback again.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top