简体   繁体   English

log4net Adonet Appender连接问题

[英]log4net Adonet Appender Connection Issue

I have developed a windows service in which I am using a timer control to perform some scheduled tasks. 我开发了一个Windows服务,我在其中使用计时器控件来执行一些计划任务。 The timer elapse event occurs every 5 minutes in which a log entry is made using log4net appender to Oracle database. 计时器过去事件每5分钟发生一次,其中使用log4net appender向Oracle数据库创建日志条目。

All works fine until the DB Server closes all connections for nightly cold backup. 一切正常,直到DB Server关闭所有连接进行夜间冷备份。 Since that time all logs in DB are missed and nothing is logged unless service is restarted even though the backup process takes less than 30 mins. 从那时起,所有DB中的日志都会丢失,除非服务重新启动,否则不会记录任何日志,即使备份过程不到30分钟。

From other posts I found that log4net uses only one connection which if lost then all subsequent logs are discarded. 从其他帖子我发现log4net只使用一个连接,如果丢失,则丢弃所有后续日志。 To remedy this I started using ReconnectOnError attribute set as true in its configuration. 为了解决这个问题,我开始在其配置中使用ReconnectOnError属性设置为true。 But unfortunately, the issue is still there. 但不幸的是,问题仍然存在。 The logs are still missing after the backup. 备份后日志仍然缺失。 I enabled tracing and found following errors but I don't know how to resolve this issue. 我启用了跟踪并发现了以下错误,但我不知道如何解决此问题。

log4net:ERROR [CustomAdoNetAppender] Exception while writing to database Oracle.DataAccess.Client.OracleException ORA-03113: end-of-file on communication channel at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) log4net:ERROR [CustomAdoNetAppender]写入数据库时​​出现异常Oracle.DataAccess.Client.OracleException ORA-03113:Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode,OracleConnection conn,IntPtr opsErrCtx,通信通道)上的文件结束Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery上的Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode,OracleConnection conn,String procedure,IntPtr opsErrCtx,OpoSqlValCtx * pOpoSqlValCtx,Object src)中的OpoSqlValCtx * pOpoSqlValCtx,Object src,String procedure) ()at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran,LoggingEvent [] events)at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent [] events)

and: 和:

log4net:ERROR [CustomAdoNetAppender] Exception while writing to database System.InvalidOperationException: Connection is already part of a local or a distributed transaction at Oracle.DataAccess.Client.OracleConnection.BeginTransaction(IsolationLevel isolationLevel) at Oracle.DataAccess.Client.OracleConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction() at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) log4net:ERROR [CustomAdoNetAppender]写入数据库时​​出现异常System.InvalidOperationException:Connection已经是Oracle.DataAccess.Client.OracleConnection.BeginDbTransaction上Oracle.DataAccess.Client.OracleConnection.BeginTransaction(IsolationLevel isolationLevel)的本地或分布式事务的一部分。 (IsolationLevel isolationLevel)位于log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent []事件)的System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()处

Any help on this highly appreciated!! 任何帮助都非常感谢!!

Personally I'd consider this to be a bug in the log4net AdoNetAppender. 我个人认为这是log4net AdoNetAppender中的一个错误。

In log4net 1.2.11 AdoNetAppender commits the cardinal sin of keeping an open connection rather than using connection pooling. 在log4net 1.2.11中, AdoNetAppender承诺保持开放连接而不是使用连接池。

Also the ReconnectOnError option looks broken: it only attempts to reconnect if the current connection state is not ConnectionState.Open , which seems wrong: I don't believe that the connection state changes when there has been an error (the enum value ConnectionState.Broken is documented in MSDN as being reserved for future versions of the product). 另外ReconnectOnError选项看起来坏了:如果当前连接状态不是ConnectionState.Open ,它只会尝试重新ConnectionState.Open ,这似乎是错误的:我不相信连接状态在出现错误时会改变(枚举值ConnectionState.Broken在MSDN中记录为保留用于产品的未来版本)。

All in all, I'd recommend you implement your own custom appender that does connection pooling properly. 总而言之,我建议您实现自己的自定义appender,以正确连接池。 It's not a very big class so would be easy to duplicate and fix. 它不是一个非常大的类,所以很容易复制和修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM