aws / aws/aws-logging-dotnet

AWS logger logs to cloudwatch twice

Open
#199 4 comments 1 reaction 0 assignees View on GitHub
bug module/logging p2 queued
Dominant language
C#
Stars
307
Forks
135
Avg merge
1d 10h
Merged PRs (30d)
4

Description

### Describe the bug

AWS logger code initializes twice in certain cases.

### Expected Behavior

It should only log once

### Current Behavior

When calling LogManager.GetLogger it calls initialization code for the logger/appender which calls
AppConfigAWSCredentials which calls GetLogger on line 33 which starts logger code initialization all over again. The second attempt finds credentials as they were set in the first one and creates a listener. The first stack finally returns in AppConfigAWSCredentials and logs that credentials were found and then continues to setup/add a listener. There are now two listeners that both react to logs coming in and send them to cloudwatch. The fix I used was to add lock/isInitialized functionality.

### Reproduction Steps

Create a project and add

private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
And use the logger somewhere in main.
Add the following sections to your config:



...



...











SystemDeveloper
us-east-1



c:\logs\awslog.txt

Additionally:
* There should be no AWS Credential providers other than the `AppConfigAWSCredentials`
* In your app.config you should add an AWS key and secret entry
```



...
```

To reproduce the issue, you need to cause the Amazon.Runtime.AppConfigAWSCredentials object to instantiate. This is done when the FallbackCredentialsFactory intantiates the CredentialsGenerators property. In other words, create a project with aws key/secret in your app.config project and have no other way to provide aws credentials so that it looks for them there.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS .NET SDK and/or Package version used

AWS.Logger.Core 3.1.0
AWS.Logger.Log4net 3.3.0
log4net 2.0.12
AWSSDK.CloudWatchLogs 3.7.2.39

### Targeted .NET Platform

4.8

### Operating System and version

Windows Server 2016 Datacenter

Contributor guide

Open the contributing guide

Research direction

Trace the initialization path from LogManager.GetLogger through AWS.Logger.Log4net.AWSAppender, AppConfigAWSCredentials, and FallbackCredentialsFactory.CredentialsGenerators. Reproduce the configuration with only app.config credentials and inspect when listeners are created. Done means logger initialization is reentrant-safe and only one listener sends each event to CloudWatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.