public void AggregateExceptionSerializeTest()
        {
            Exception aggregateError = null;

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
            Func <Task> asyncFunc = async() =>
            {
                File.ReadAllText("some invalid path.txt");
                Assert.Fail();
            };
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

            try
            {
                asyncFunc().Wait();
            }
            catch (Exception ex)
            {
                aggregateError = ex;
            }

            var exceptionDumper = new JsonExceptionDumper();

            Debug.Assert(aggregateError != null, "aggregateError != null");
            var dto = exceptionDumper.Dump <ExceptionDto>(aggregateError);
            TestContext.WriteLine(JsonConvert.SerializeObject(dto, JsonDefaults.JsonConfigSerializerSource.Settings));
        }
        public void SimpleSerializeTest()
        {
            Exception simpleError = null;

            try
            {
                File.ReadAllText("some invalid path.txt");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                simpleError = ex;
            }

            var exceptionDumper = new JsonExceptionDumper();
            var dto             = exceptionDumper.Dump <ExceptionDto>(simpleError);

            TestContext.WriteLine(JsonConvert.SerializeObject(dto, JsonDefaults.JsonConfigSerializerSource.Settings));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds <c>exception</c> dump to the json entry.
        /// </summary>
        /// <param name="builder">Entry <c>builder</c>.</param>
        /// <param name="exception">Exception to log.</param>
        /// <returns>The same <c>builder</c> for fluent syntax.</returns>
        public static ILogEntryBuilder Exception(this ILogEntryBuilder builder, Exception exception)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            var exceptionDump = new JsonExceptionDumper().Dump <ExceptionDto>(exception);

            return(new DelegateLogEntryBuilderForLogEntry(
                       builder,
                       e =>
            {
                e.Exception = exceptionDump;
                return e;
            }));
        }