/// <summary> /// Submits an exception as a fault to the ESB Exception database /// </summary> /// <remarks> /// The majority of the properties populated in the fault are needed for the WCF-generated /// fault to look the same as an ESB-generated fault, as null values are allowed in the /// database, but will prevent records showing in the ESB management portal. /// </remarks> /// <param name="serviceProviderName">Name of the service provider</param> /// <param name="serviceName">Name of the service submitting the fault</param> /// <param name="faultDescription">Description or fault/error message</param> /// <param name="severity">Severity of fault</param> /// <param name="ex">Exception that was caught</param> public static void SubmitFault(string serviceProviderName, string serviceName, string faultDescription, FaultSeverity severity, Exception ex) { DateTime now = DateTime.Now; //populate the header: FaultMessageHeader header = new FaultMessageHeader(); header.DateTime = now.ToString(); header.MachineName = Environment.MachineName; header.Application = ServiceProviderErrorHandlerConfiguration.Current.BizTalkApplication; header.ServiceName = string.Format("{0}.{1}", serviceProviderName, serviceName); header.ErrorType = ServiceProviderErrorHandlerConfiguration.Current.ErrorType; header.FailureCategory = ServiceProviderErrorHandlerConfiguration.Current.FailureCategory; header.FaultCode = ServiceProviderErrorHandlerConfiguration.Current.FaultCode; header.FaultSeverity = (int)severity; header.FaultDescription = faultDescription; header.FaultGenerator = ServiceProviderErrorHandlerConfiguration.Current.FaultGeneratorName; header.Description = string.Format("Fault occurred in provider: {0}, processing service: {1}", serviceProviderName, serviceName); header.MessageID = GetDeterministicGuid("{0}_{1}_{2}", serviceProviderName, serviceName, now.Ticks).ToString(); header.ActivityIdentity = GetDeterministicGuid("{0}_{1}", serviceProviderName, serviceName).ToString(); header.ServiceInstanceID = GetDeterministicGuid(serviceProviderName).ToString(); //OperationContext is thread static, no may be null if call from child threads: if (OperationContext.Current == null) { header.Scope = "Worker thread"; } else { header.Scope = OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri.AbsoluteUri; } //populate exception details: FaultMessageExceptionObject faultException = new FaultMessageExceptionObject(); faultException.Source = ex.Source; faultException.StackTrace = ex.StackTrace; faultException.Message = ex.Message; faultException.Type = ex.GetType().FullName; if (ex.TargetSite != null) { faultException.TargetSite = ex.TargetSite.ToString(); } if (ex.InnerException != null) { faultException.InnerExceptionMessage = ex.InnerException.Message; } else { //ESB uses the fault code here: faultException.InnerExceptionMessage = ServiceProviderErrorHandlerConfiguration.Current.FaultCode; } FaultMessage message = new FaultMessage(); message.Header = header; message.ExceptionObject = faultException; SubmitFault(message); }