示例#1
0
 /// <inheritdoc/>
 protected override void FlushAsync(AsyncContinuation asyncContinuation)
 {
     try
     {
         _core.Flush();
         asyncContinuation(null);
     }
     catch (Exception ex)
     {
         asyncContinuation(ex);
     }
 }
示例#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
        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();
            }
        }
示例#4
0
 /// <inheritdoc />
 public override bool Flush(int millisecondsTimeout)
 {
     _core?.Flush();
     return(base.Flush(millisecondsTimeout));
 }