Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        private bool disposedValue = false; // To detect redundant calls

        /// <summary>
        /// Disposable Pattern
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    try
                    {
                        _core.Close();
                    }
                    catch (Exception)
                    {
                        // .. and as ugly as THIS is, .Dispose() methods shall not throw exceptions
                    }
                }

                disposedValue = true;
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 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,
                LogStreamNameSuffix = LogStreamNameSuffix,
                LibraryLogFileName  = LibraryLogFileName
            };

            _core = new AWSLoggerCore(config, "NLog");
            _core.LogLibraryAlert += AwsLogLibraryAlert;
        }