/// <summary> /// Traces the specified exception. /// </summary> /// <param name="exception">The specified exception.</param> /// <param name="traceEventType">The optional event type.</param> /// <param name="errorCode">The specified code. Optional. By default it is assumed that this is a global level caught exception.</param> /// <param name="context">Trace contextual information.</param> /// <remarks>This is the preferred method to log exceptions caught at global level.</remarks> public void TraceException(Exception exception, TraceEventType traceEventType = TraceEventType.GlobalLevelCaughtError, int errorCode = ErrorCodes.GlobalLevelError, TraceContext context = null) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } var baseException = exception as BaseException; int realCode = baseException?.ErrorCode ?? errorCode; string message = exception.Message; // try to find our own exceptions supposed to be more meaningfull Exception innerException = GetInnerException(exception, 10); if (innerException != exception) { message += " : " + innerException.Message; var internalBaseException = innerException as BaseException; realCode = internalBaseException?.ErrorCode ?? realCode; } var loadException = innerException as ReflectionTypeLoadException; if (loadException != null) { foreach (var exceptionMessage in loadException.LoaderExceptions.Select(e => e.Message).Distinct()) { message += "\r\n- " + exceptionMessage; } } TraceContext traceContext = context ?? TraceContext.Create(Constants.TraceParameter.ErrorCode, realCode); TraceInternal(TraceCategory.Error, realCode, traceEventType, null, null, null, exception, message, traceContext); }
/// <summary> /// Called after the operation has returned but before the reply message is sent. /// </summary> /// <param name="reply">The reply message. This value is null if the operation is one way.</param> /// <param name="correlationState"> /// The correlation object returned from the /// <see /// cref="M:System.ServiceModel.Dispatcher.IDispatchMessageInspector.AfterReceiveRequest(System.ServiceModel.Channels.Message@,System.ServiceModel.IClientChannel,System.ServiceModel.InstanceContext)" /> /// method. /// </param> public void BeforeSendReply(ref Message reply, object correlationState) { if (_tracer == null) { return; } TraceContext context = TraceContext.Create(Constants.TraceParameter.Name, _webServiceName) .Add(Constants.TraceParameter.Operation, _operationName); string eventName = _webServiceName + "." + _operationName; string message = string.Format(CultureInfo.CurrentCulture, InternalMessages.WebServiceResponse, eventName); _tracer.TraceStopPerformance(_serverSideStartTime, message, TraceEventType.HttpResponse, eventName, context); }