Exemple #1
0
        public void ActionMethodUnhandledExceptionLogEntry()
        {
            var server = new TestServerBuilder()
                         .AddGraphType <LogTestController>()
                         .Build();

            var package      = server.CreateFieldContextBuilder <LogTestController>(nameof(LogTestController.ExecuteField2));
            var graphMethod  = TemplateHelper.CreateActionMethodTemplate <LogTestController>(nameof(LogTestController.ExecuteField2)) as IGraphMethod;
            var fieldRequest = package.FieldRequest;

            var result = new object();

            var exception = new Exception("inner error");
            var entry     = new ActionMethodUnhandledExceptionLogEntry(graphMethod, fieldRequest, exception);

            Assert.AreEqual(LogEventIds.ControllerUnhandledException.Id, entry.EventId);
            Assert.AreEqual(fieldRequest.Id, entry.PipelineRequestId);
            Assert.AreEqual(graphMethod.Parent.InternalFullName, entry.ControllerTypeName);
            Assert.AreEqual(graphMethod.Name, entry.ActionName);
            Assert.IsNotNull(entry.ToString());

            var exceptionEntry = entry.Exception as ExceptionLogItem;

            Assert.IsNotNull(exceptionEntry);
            Assert.AreEqual(exception.Message, exceptionEntry.ExceptionMessage);
            Assert.AreEqual(exception.StackTrace, exceptionEntry.StackTrace);
            Assert.AreEqual(exception.GetType().FriendlyName(true), exceptionEntry.TypeName);
        }
Exemple #2
0
        /// <inheritdoc />
        public virtual void ActionMethodUnhandledException(IGraphMethod action, IDataRequest request, Exception exception)
        {
            if (!this.IsEnabled(LogLevel.Error))
            {
                return;
            }

            var entry = new ActionMethodUnhandledExceptionLogEntry(action, request, exception);

            this.LogEvent(LogLevel.Error, entry);
        }