gpt4 book ai didi

c# - ExceptionShielding 有更好的替代品吗?

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:43 25 4
gpt4 key购买 nike

我们公司正在从 Microsoft.Practices.Enterprise.Library 日志记录和异常处理转向使用 Log4Net。我删除了所有标准日志记录和异常处理调用,将它们替换为 Log4Net 等效项,但是当我删除 Practices Dll 时,我注意到我们将它们用于 ExceptionShielding:

using System;
using System.ServiceModel;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;

namespace CRM.WCFServices.LeadIntegration.ServiceContracts
{
/// <summary>
/// Interface for systems external to CRM to interact with outbound calls.
/// </summary>
[ExceptionShielding("WCF Exception Shielding")]
[ServiceContract]
public interface IOutboundIntegrationService
{
#region Contracts

[OperationContract]
[FaultContract(typeof (Common.Services.WCF.FaultContracts.ServiceFault))]
void SendOutboundData(string entityName, Guid entityId, DateTime modifiedOn, Guid modifiedBy,
string crmOrganization);

#endregion
}
}

基本问题是“我怎样才能安全地删除它?”其中涉及回答大部分问题:

  1. 它有什么作用? - 根据我的阅读,它允许您在 WCF 服务返回给客户端之前捕获任何异常,允许您记录异常并创建不包含任何安全敏感信息的异常。
  2. 它在接口(interface)上是否有效(它在 上的任何地方都没有被引用?
  3. Log4Net 有类似的东西吗?

最佳答案

如果我没记错的话,Exception Shielding 的目的功能是

  1. 防止跨服务边界发布实现细节,或者
  2. 允许开发人员偷懒,不要在服务边界的所有服务操作周围添加 try/catch block 。

做出你的选择。

如果我没记错的话,那么您需要做的就是在 web.config 中将 includeExceptionDetailInFaults 设置为 false,或者在您的服务方法周围放置 try/catch block :

try
{
// service code
}
catch (Exception ex)
{
// Log the exception
throw new FaultException("Unknown service failure");
}

关于c# - ExceptionShielding 有更好的替代品吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20666849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com