コード例 #1
0
        /// <summary>
        /// Initialize the appender based on the options set.
        /// </summary>
        public override void ActivateOptions()
        {
            if (_core != null)
            {
                _core.Close();
                _core = null;
            }

            var config = new AWSLoggerConfig(this.LogGroup)
            {
                DisableLogGroupCreation = DisableLogGroupCreation,
                Region              = Region,
                ServiceUrl          = ServiceUrl,
                Credentials         = Credentials,
                Profile             = Profile,
                ProfilesLocation    = ProfilesLocation,
                BatchPushInterval   = BatchPushInterval,
                BatchSizeInBytes    = BatchSizeInBytes,
                MaxQueuedMessages   = MaxQueuedMessages,
                LogStreamNameSuffix = LogStreamNameSuffix,
                LogStreamNamePrefix = LogStreamNamePrefix,
                LibraryLogErrors    = LibraryLogErrors,
                LibraryLogFileName  = LibraryLogFileName
            };

            _core = new AWSLoggerCore(config, "Log4net");
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override void InitializeTarget()
        {
            if (_core != null)
            {
                _core.Close();
                _core = null;
            }

            var config = new AWSLoggerConfig(RenderSimpleLayout(LogGroup, nameof(LogGroup)))
            {
                DisableLogGroupCreation = DisableLogGroupCreation,
                Region              = RenderSimpleLayout(Region, nameof(Region)),
                ServiceUrl          = RenderSimpleLayout(ServiceUrl, nameof(ServiceUrl)),
                Credentials         = Credentials,
                Profile             = RenderSimpleLayout(Profile, nameof(Profile)),
                ProfilesLocation    = RenderSimpleLayout(ProfilesLocation, nameof(ProfilesLocation)),
                BatchPushInterval   = BatchPushInterval,
                BatchSizeInBytes    = BatchSizeInBytes,
                MaxQueuedMessages   = MaxQueuedMessages,
                LogStreamNameSuffix = RenderSimpleLayout(LogStreamNameSuffix, nameof(LogStreamNameSuffix)),
                LogStreamNamePrefix = RenderSimpleLayout(LogStreamNamePrefix, nameof(LogStreamNamePrefix)),
                LibraryLogErrors    = LibraryLogErrors,
                LibraryLogFileName  = LibraryLogFileName,
                FlushTimeout        = FlushTimeout
            };

            _core = new AWSLoggerCore(config, "NLog");
            _core.LogLibraryAlert += AwsLogLibraryAlert;
        }
        public void UnicodeCharTest()
        {
            var testChar  = '∀';
            var charCount = 240000;
            var message   = new string(testChar, charCount);
            var bytesSize = Encoding.UTF8.GetByteCount(message);

            Assert.Equal((bytesSize / 256000) + 1, AWSLoggerCore.BreakupMessage(message).Count);
        }
コード例 #4
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();
            }
        }
        public void DefaultConfig()
        {
            var config = new AWSLoggerConfig
            {
            };
            var streamName = AWSLoggerCore.GenerateStreamName(config);

            var tokens = SplitStreamName(streamName);

            Assert.Equal(2, tokens.Length);

            Assert.True(IsTokenDate(tokens[0]));
            Assert.True(IsTokenGuid(tokens[1]));
        }
        public void SuffixSet()
        {
            var config = new AWSLoggerConfig
            {
                LogStreamNameSuffix = "TheSuffix"
            };
            var streamName = AWSLoggerCore.GenerateStreamName(config);

            var tokens = SplitStreamName(streamName);

            Assert.Equal(2, tokens.Length);

            Assert.True(IsTokenDate(tokens[0]));
            Assert.Equal(config.LogStreamNameSuffix, tokens[1]);
        }
コード例 #7
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();
            }
        }
コード例 #8
0
        protected override void InitializeTarget()
        {
            if (_core != null)
            {
                _core.Close();
                _core = null;
            }

            var config = new AWSLoggerConfig(this.LogGroup)
            {
                Region            = Region,
                Credentials       = Credentials,
                Profile           = Profile,
                ProfilesLocation  = ProfilesLocation,
                BatchPushInterval = BatchPushInterval,
                BatchSizeInBytes  = BatchSizeInBytes,
                MaxQueuedMessages = MaxQueuedMessages
            };

            _core = new AWSLoggerCore(config, "NLog");
        }
コード例 #9
0
        /// <summary>
        /// Initialize the appender based on the options set.
        /// </summary>
        public override void ActivateOptions()
        {
            if (_core != null)
            {
                _core.Close();
                _core = null;
            }

            var config = new AWSLoggerConfig(this.LogGroup)
            {
                Region            = Region,
                Credentials       = Credentials,
                Profile           = Profile,
                ProfilesLocation  = ProfilesLocation,
                BatchPushInterval = BatchPushInterval,
                BatchSizeInBytes  = BatchSizeInBytes,
                MaxQueuedMessages = MaxQueuedMessages
            };

            _core = new AWSLoggerCore(config, "Log4net");
        }
コード例 #10
0
        protected override void InitializeTarget()
        {
            if (_core != null)
            {
                _core.Close();
                _core = null;
            }

            var config = new AWSLoggerConfig(this.LogGroup)
            {
                Region              = Region,
                Credentials         = Credentials,
                Profile             = Profile,
                ProfilesLocation    = ProfilesLocation,
                BatchPushInterval   = BatchPushInterval,
                BatchSizeInBytes    = BatchSizeInBytes,
                MaxQueuedMessages   = MaxQueuedMessages,
                LogStreamNameSuffix = LogStreamNameSuffix,
                LibraryLogFileName  = LibraryLogFileName
            };

            _core = new AWSLoggerCore(config, "NLog");
            _core.LogLibraryAlert += AwsLogLibraryAlert;
        }
コード例 #11
0
 /// <summary>
 /// Constructor called by AWSLoggerSeriLoggerExtension
 /// </summary>
 /// <param name="loggerConfiguration"></param>
 /// <param name="iFormatProvider"></param>
 public AWSSink(AWSLoggerConfig loggerConfiguration, IFormatProvider iFormatProvider = null, ITextFormatter textFormatter = null)
 {
     _core          = new AWSLoggerCore(loggerConfiguration, "SeriLogger");
     _iformatDriver = iFormatProvider;
     _textFormatter = textFormatter;
 }
コード例 #12
0
 public AWSTraceListener(AWSLoggerConfig config)
 {
     _core = new AWSLoggerCore(config);
 }
        public void AsciiTest()
        {
            var message = new string('a', 240000);

            Assert.Single(AWSLoggerCore.BreakupMessage(message));
        }