示例#1
0
        public async Task LogsExceptionAsync()
        {
            IHost host = null;

            try
            {
                host = DefaultHostBuilder.CreateHostBuilder().Build();
                await host.StartAsync();

                IContextExceptionLogger exceptionLogger = host.Services.GetRequiredService <IContextExceptionLogger>();
                try
                {
                    ThrowsException();
                }
                catch (Exception e)
                {
                    exceptionLogger.Log(e, null);
                }

                var errorEvent = ErrorEventEntryVerifiers.VerifySingle(ErrorEventEntryPolling.Default, _testId);
                ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(
                    errorEvent, _testId, nameof(ThrowsException), verifyHttpContext: false);
            }
            finally
            {
                if (host is object)
                {
                    await host.StopAsync();
                }
            }
        }
示例#2
0
        public async Task LogsAsync()
        {
            IHost host = null;

            try
            {
                host = DefaultHostBuilder.CreateHostBuilder().Build();
                await host.StartAsync();

                ILogger logger = host.Services.GetRequiredService <ILogger <Program> >();
                logger.LogInformation(_testId);

                LoggingSnippets.PollAndVerifyLog(LogEntryPolling.Default, _startTime, _testId);
            }
            finally
            {
                if (host is object)
                {
                    await host.StopAsync();
                }
            }
        }