/// <summary>
        /// Append method of AppenderSkeleton is called when a new message gets logged.
        /// </summary>
        /// <param name="loggingEvent">
        /// LoggingEvent containing information about the log message.
        /// </param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (_core == null)
            {
                return;
            }

            _core.AddMessage(RenderLoggingEvent(loggingEvent));
        }
Пример #2
0
        public async Task TestCoreWithDisableLogGroupCreation()
        {
            var logGroupName = nameof(TestCoreWithDisableLogGroupCreation);

            using (var client = new AmazonCloudWatchLogsClient(RegionEndpoint.USWest2))
            {
                var config = new AWSLoggerConfig(logGroupName)
                {
                    Region = RegionEndpoint.USWest2.SystemName,
                    DisableLogGroupCreation = true,
                };

                var resourceNotFoundPromise = new TaskCompletionSource <bool>();  // true means we saw expected exception; false otherwise
                var core = new AWSLoggerCore(config, "unit");
                core.LogLibraryAlert += (sender, e) =>
                {
                    if (e.Exception is ResourceNotFoundException)
                    {
                        // saw EXPECTED exception.
                        resourceNotFoundPromise.TrySetResult(true);
                    }
                    else if (e.Exception != null)
                    {
                        _output.WriteLine("Was not expecting to see exception: {0} @{1}", e.Exception, e.ServiceUrl);
                    }
                };

                var tsk = Task.Factory.StartNew(() =>
                {
                    core.AddMessage("Test message added at " + DateTimeOffset.UtcNow.ToString());
                    core.Flush();
                });

                await Task.WhenAny(tsk, resourceNotFoundPromise.Task).ConfigureAwait(false);

                resourceNotFoundPromise.TrySetResult(false);
                Assert.True(await resourceNotFoundPromise.Task);

                // now we create the log group, late.
                await client.CreateLogGroupAsync(new CreateLogGroupRequest
                {
                    LogGroupName = logGroupName
                });

                _testFixure.LogGroupNameList.Add(logGroupName);

                // wait for the flusher task to finish, which should actually proceed OK, now that we've created the expected log group.
                await tsk.ConfigureAwait(false);

                core.Close();
            }
        }
Пример #3
0
        /// <summary>
        /// Method called to pass the LogEvent to the AWSLogger Sink
        /// </summary>
        /// <param name="logEvent"></param>
        public void Emit(LogEvent logEvent)
        {
            var message = RenderLogEvent(logEvent);

            if (logEvent.Exception != null)
            {
                message = string.Concat(message, Environment.NewLine, logEvent.Exception.ToString(), Environment.NewLine);
            }
            else
            {
                message = string.Concat(message, Environment.NewLine);
            }
            _core.AddMessage(message);
        }
        /// <summary>
        /// Method called to pass the LogEvent to the AWSLogger Sink
        /// </summary>
        /// <param name="logEvent"></param>
        public void Emit(LogEvent logEvent)
        {
            var message = RenderLogEvent(logEvent);

            // If there is no custom formatter passed that would have taken care of logging the exception then append the
            // exception to the log if one exists.
            if (_textFormatter == null && logEvent.Exception != null)
            {
                message = string.Concat(message, Environment.NewLine, logEvent.Exception.ToString(), Environment.NewLine);
            }
            else
            {
                message = string.Concat(message, Environment.NewLine);
            }
            _core.AddMessage(message);
        }
Пример #5
0
        public void TestCoreWithoutDisableLogGroupCreation()
        {
            var logGroupName = nameof(TestCoreWithoutDisableLogGroupCreation) + DateTime.UtcNow.Ticks; // this one will have to be auto-created.

            using (var client = new AmazonCloudWatchLogsClient(RegionEndpoint.USWest2))
            {
                var config = new AWSLoggerConfig(logGroupName)
                {
                    Region = RegionEndpoint.USWest2.SystemName,
                    DisableLogGroupCreation = false,
                };

                var core = new AWSLoggerCore(config, "unit");
                core.AddMessage("Test message added at " + DateTimeOffset.UtcNow.ToString());
                core.Flush();
                _testFixure.LogGroupNameList.Add(logGroupName); // let's enlist the auto-created group for deletion.
                core.Close();
            }
        }
Пример #6
0
        /// <inheritdoc/>
        protected override void Write(LogEventInfo logEvent)
        {
            var message = RenderLogEvent(this.Layout, logEvent);

            _core.AddMessage(message);
        }
Пример #7
0
 private void Log(TraceEventCache eventCache, string source, TraceEventType eventType, int eventId, params object[] data)
 {
     _core.AddMessage(data[0].ToString());
 }