代码之家  ›  专栏  ›  技术社区  ›  Tobias Hertkorn

禁止显示内部log4net错误消息

  •  2
  • Tobias Hertkorn  · 技术社区  · 16 年前

    我有一个控制台应用程序,除了平面文件外,还应该尽最大努力地记录到数据库中。当没有网络连接(因此没有到数据库的连接)时,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错误消息?重新编译可以,但如果可能的话,我更喜欢基于配置的设置。

    1 回复  |  直到 16 年前
        1
  •  6
  •   Mark Rushakoff    16 年前

    我还没有测试过,但我很确定 the QuietMode property 做你想做的。