log4net到SQLServer:如果数据库不可用怎么办? [英] log4net to SQLServer : what happens if database is unavailable?

查看:187
本文介绍了log4net到SQLServer:如果数据库不可用怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个log4net ado附加程序,它正在写入SQL Server数据库.我喜欢它,我认为它很整洁.在将其发送到生产环境之前,我想知道如果数据库关闭,行为将会如何.

I have a log4net ado appender writing to a SQL Server database. I like it, I think it's neat. Before I send it into production, I want to know what the behaviour will be if the database goes down.

我不希望应用程序停止,因为日志数据库不可用.我以为log4net只会静默地失败并且什么也不做,至少那是我希望的.任何人都可以确认这一点或(更好)为我指出一些可以确认这一点的文档吗?

I don't want the application to stop because the logging database is unavailable. I am presuming that log4net will just silently fail and not do anything, at least that's what I'm hoping. Can anyone confirm this or (better) point me to some documentation that will confirm this?

推荐答案

该附加程序(例如我所知道的所有log4net附加程序)将在无提示的情况下失败,从而停止日志记录.您可以将附加程序配置为尝试通过以下方式重新连接:

The appender (like all log4net appenders that I am aware of) will fail silently and thus stop logging. You can configure the appender to try to reconnect though:

<reconnectonerror value="True" />

在这种情况下,您可能希望在数据库连接字符串中指定连接超时:

In that case you probably want to specify a connection time out in your db connection string:

Connect Timeout=1

如果不这样做,则在数据库处于脱机状态时,应用程序将非常慢.

If you do not do that your application will be very slow if the db is offline.

这篇关于log4net到SQLServer:如果数据库不可用怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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