Exemplo n.º 1
0
        public Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            var entry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry(exception.Message, logCategory, 0, 100, TraceEventType.Error, defaultTitle, null);

            foreach (DictionaryEntry dataEntry in exception.Data)
            {
                if (dataEntry.Key is string)
                {
                    entry.ExtendedProperties.Add(dataEntry.Key as string, dataEntry.Value);
                }
            }

            Type[]          types       = new Type[] { typeof(TextWriter), typeof(Exception), typeof(Guid) };
            ConstructorInfo constructor = formatterType.GetConstructor(types);

            using (StringWriter writer = new StringWriter())
            {
                var exceptionFormatter = (ExceptionFormatter)constructor.Invoke(new object[] { writer, exception, handlingInstanceId });
                exceptionFormatter.Format();
                entry.AddErrorMessage(writer.GetStringBuilder().ToString());
            }

            Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(entry);

            return(exception);
        }