NLog是否有故障转移机制? [英] Is there a fail over mechanism with NLog?

查看:111
本文介绍了NLog是否有故障转移机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NLog进行数据库记录.如果数据库关闭,那么我只需要它即可登录到文件.有办法吗?

I am using NLog for DB logging. If the DB is down then I only need it to log to a file. Is there a way to do this?

我不想在文件和数据库中记录日志条目.如果数据库目标仅无法记录日志(如果数据库关闭),那么我是否必须登录到该文件. Nlog是否有任何故障转移或后备功能?

I don't want to record log entries log in both a file and the DB. If the DB target fails to log (if DB is down) only then do I have to log to the file. Is there any fail over or fallback feature with Nlog?

推荐答案

是的,有一种方法.它称为FallbackGroup.

Yes, there is a way. It's called a FallbackGroup.

文档可在此处找到: https://github.com/nlog/NLog /wiki/FallbackGroup-target

以下是一个公然而as愧地摘自文档的示例:

Here is an example taken blatantly and ashamedly from the documentation:

<target xsi:type="FallbackGroup" 
        name="mail"
        returnToFirstOnSuccess="true">
    <target xsi:type="Mail"
            name="mailserver1"
            subject="Layout"
            to="Layout"
            from="Layout"
            smtpServer="mx1.example.com" 
            smtpPort="Integer"
            layout="Layout" />
    <target xsi:type="Mail"
            name="mailserver2" 
            subject="Layout"
            to="Layout"
            from="Layout"
            smtpServer="mx2.example.com" 
            smtpPort="Integer"
            layout="Layout" />
</target>
<rules>
  <logger name="*" minlevel="Trace" writeTo="mail" />
</rules>

如果第一个邮件服务器失败,它将尝试另一个邮件服务器.如果成功,它也会返回第一个目标.

It'll try another mail server if the first fails. It'll also return to the first target if it's successful.

我从未在生产中使用过它,也许文档中的其他选项可以帮助您根据问题进行微调.

I never used it in production, maybe the other options in the documentation can help you fine tune it to your problem.

这篇关于NLog是否有故障转移机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆