Ejemplo n.º 1
0
        public void ExceptionData_CreateExceptionData_ShouldCreateAValidExceptionData()
        {
            var obj  = default(ExceptionData);
            var obj2 = default(ExceptionData);
            var obj3 = default(ExceptionData);

            try
            {
                throw new Exception("This is a Test");
            }
            catch (Exception ex)
            {
                obj = new ExceptionData(ex);
            }

            try
            {
                throw new OutOfMemoryException("This is 2 a Test");
            }
            catch (Exception ex)
            {
                obj2 = new ExceptionData(ex, true);
            }

            try
            {
                throw new IndexOutOfRangeException("This is a Test #3");
            }
            catch (Exception ex)
            {
                obj3 = new ExceptionData(ex, true);
            }

            obj.Should().NotBeNull(null, null);
            obj.IsUnhandledException.Should().BeFalse(null, null);
            obj.GetAssemblyInfo().Should().NotBeNullOrEmpty(null, null);
            obj.CurrentException.Should().BeOfType <Exception>(null, null);
            obj.CurrentException.Message.Should().Be("This is a Test", null, null);
            obj.SysInfoToString().Should().NotBeNullOrEmpty(null, null);
            obj.GetErrorLocations().Count.Should().BeGreaterThan(0, null, null);
            obj.ExceptionToString().Should().NotBeNullOrEmpty(null, null);
            obj.GetExceptionType().Should().Be("Exception Type:           " + obj.CurrentException.GetType().FullName, null, null);
            obj.GetEnhancedStackTrace().Should().NotBeNullOrEmpty(null, null);

            obj2.Should().NotBeNull(null, null);
            obj2.IsUnhandledException.Should().BeTrue(null, null);
            obj2.GetAssemblyInfo().Should().NotBeNullOrEmpty(null, null);
            obj2.CurrentException.Should().BeOfType <OutOfMemoryException>(null, null);
            obj2.CurrentException.Message.Should().Be("This is 2 a Test", null, null);
            obj2.SysInfoToString().Should().NotBeNullOrEmpty(null, null);
            obj2.GetErrorLocations().Count.Should().BeGreaterThan(0, null, null);
            obj2.ExceptionToString().Should().NotBeNullOrEmpty(null, null);
            obj2.GetExceptionType().Should().Be("Exception Type:           " + obj2.CurrentException.GetType().FullName, null, null);
            obj.GetEnhancedStackTrace().Should().NotBeNullOrEmpty(null, null);

            obj3.IsUnhandledException.Should().BeTrue(null, null);
        }
Ejemplo n.º 2
0
        private string CreateLogContent()
        {
            StringBuilder sb = new StringBuilder();
            List <ExceptionLocationData> _GetErrorLocations = null;

            sb.AppendLine(">>>> INICIO DE LOG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            sb.AppendLine(string.Empty);
            sb.AppendLine(DateTime.Now.ToString(CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern));
            sb.Append("Se ha capturado una excepcion ");
            sb.AppendLine((currentError.IsUnhandledException ? "NO MANEJADA" : "MANEJADA"));
            sb.AppendLine(string.Empty);
            sb.AppendLine("[Mini Dump File]");

            if (SaveMiniDump)
            {
                sb.Append("Se ha intentado crear un archivo mini dump en la ubicacion:");
                sb.AppendLine(string.Empty);

                sb.Append(MiniDumpPath);
                sb.AppendLine(string.Empty);
                sb.AppendLine(string.Empty);
            }
            else
            {
                sb.AppendLine("No se ha guardado un archivo mini dump");
                sb.AppendLine(string.Empty);
            }

            sb.AppendLine("[Screenshot File]");

            if (TakeScreenShot)
            {
                sb.Append("Se ha intentado crear una impresion de pantalla del error en:");
                sb.AppendLine(string.Empty);
                sb.Append(screenShotPath);
                sb.AppendLine(string.Empty);
                sb.AppendLine(string.Empty);
            }
            else
            {
                sb.AppendLine("No se ha tomado una impresion de pantalla");
                sb.AppendLine(string.Empty);
            }

            sb.AppendLine(new String('_', 50));
            sb.AppendLine("A continuacion se muestra la informacion recopilada por el sistema de errores:");
            sb.AppendLine(new String('_', 50));
            sb.AppendLine(string.Empty);
            sb.Append(currentError.ExceptionToString());

            sb.AppendLine(currentError.SysInfoToString());
            sb.AppendLine(currentError.GetAssemblyInfo());

            _GetErrorLocations = currentError.GetErrorLocations();

            if (_GetErrorLocations != null)
            {
                if (_GetErrorLocations.Count > 0)
                {
                    sb.AppendLine("[Ubicaciones de los errores]");

                    foreach (ExceptionLocationData ErrLocation in _GetErrorLocations)
                    {
                        sb.Append("Archivo: ");
                        sb.Append(ErrLocation.FileName);
                        sb.Append(Environment.NewLine);
                        sb.Append("Metodo: ");
                        sb.Append(ErrLocation.Method);
                        sb.Append(Environment.NewLine);
                        sb.Append("Linea: ");
                        sb.Append(ErrLocation.Line);
                        sb.AppendLine(string.Empty);
                        sb.AppendLine(new String('_', 30));
                    }
                }
            }

            sb.AppendLine(string.Empty);
            sb.AppendLine("[Stack Trace Information]");
            sb.AppendLine(currentError.GetEnhancedStackTrace());
            sb.AppendLine(string.Empty);

            sb.AppendLine("<<<< FIN DE LOG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            return(sb.ToString());;
        }