我有一个控制台应用程序,除了平面文件外,还应尽最大努力记录到数据库。当没有网络连接(因此没有连接到数据库)时,log4net会输出错误。
log4net:ERROR [AdoNetAppender] Could not open database connection [Data Source=...]
System.Data.SqlClient.SqlException: A network-related or instance-specific
error occurred while establishing a connection to SQL Server. The server
was not found or was not accessible. Verify that the instance name is correct
and that SQL Server is configured to allow remote connections. (provider:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at ...
我不想在控制台中看到该错误。有没有办法抑制内部log4net错误消息?重新编译可以,但如果可能的话,我会优先选择基于配置的设置。