Closed fbouteruche closed 1 month ago
Hi @fbouteruche,
Thanks for posting the issue.
As per API documentation for Amazon.Runtime.ClientConfig, the settings LogResponse
and LogMetrics
are just the boolean
flags. The configuration also needs other settings on where to log the output. Following references could be helpful:
You are correctly setting the following properties of the AWSConfigs object to enable logging.
You may also refer aws-logging-dotnet which has plugins for popular .NET logging frameworks that integrate with Amazon Web Services. The plugins use the Amazon CloudWatch Logs service to write log data to a configured log group. ASP.NET Core Logging might be of interest to you.
Please review above information and let me know if this issue could be closed.
Thanks, Ashish
Hi @ashishdhingra
Thanks for your quick answer and confirming that the additional steps are required.
However, I must point out that the link you provided are not relevant for .NET Core. A major change concerning configuration management has raised with the release of .NET Core as mentioned here https://aws.amazon.com/fr/blogs/developer/configuring-aws-sdk-with-net-core/.
This change led to the release of AWSSDK.Extensions.NETCore.Setup.
Today, when you are developing a netcoreapp3.1web app, the following value are not read from the config file anymore:
This is mainly due to the fact that the GetConfig method from the AWSConfigs .netstandard implementation return null https://github.com/aws/aws-sdk-net/blob/e729b1958a37b62d433459ad41df202f544e09b6/sdk/src/Core/_netstandard/AWSConfigs.netstandard.cs#L38 .
So, while with .NET Framework, you can activate and configure log only through the configuration file, with .NET Core you are forced to mix both config file and code configuration which is a pity.
Concerning the use of aws-logging-dotnet, one doesn't necessarily want to send logs to CloudWatch, especially in early development stage when you are debugging on your own laptop.
To sum up, I don't think you can close the issue. I think there is a documentation work needed here as well a fix for loading all the log configuration from the appsettings.json file in .NET Core.
Hi @fbouteruche,
Thanks for your inputs. I definitely see the need here to update the documentation. For reading from appsettings.json
file, while I cannot commit on the timeline when it could be implemented (or if it would be implemented), I would need to discuss with developer on whether to treat this as a bug
or feature-request
.
Thanks, Ashish
+1 for this this issue. We are experiencing the exact difficulties @fbouteruche
+1 for this this issue. We are experiencing the exact difficulties @fbouteruche
+1 for this this issue. We are experiencing the exact difficulties @fbouteruche when it is expected to be solved?
Is there any indication this is on track to be fixed? The fact the "needs reproduction" label was only recently removed, doesn't fill me with confidence... And logging is an area where I personally have little tolerance for issues and friction.
To enable logging in your .NET core application, you must inject the service client into .NET's dependency injection system. In NetCore the configuration is an instance level object which means we don't have a global way of accessing the configuration like we do in NetFramework, where the configuration is a global singleton. This is why you see that in AWSConfigs.NetStandard
we just return null for GetConfig
, because we expect the user to pass the IConfiguration
to the SDK by using the NetCoreSetup package. To have the SDK read the appsettings.json file in NetCore, you have to add this line to your application
builder.Services.AddAWSService<IAmazonS3>();
Then, in your application you can then see that Config.LogResponse
will reflect that which you set in appsettings.Development.json
.
If you don't want to use DI in your application you can add something like
configuration.GetAWSOptions().CreateServiceClient<IAmazonDynamoDB>(); // configuration being an instance of IConfiguration
Please let me know if that helps or you have any follow up questions.
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
Description
As a .NET developer, I want to active SDK call response log to System.Diagnostics or to Console to log locally the responses to all SDK API calls when I'm debugging a .NET Core Web App.
I read carefully the documentation for .NET Core here https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/net-dg-config-netcore.html and added the following section to my appsettings.Development.json file :
At this point, I except to see in the console or in the Debug Window of Visual Studio the logs of the responses to AWS API.
From my exploration of the SDK, I discovered that setting the following properties of the AWSConfigs object in addition to adding the appsettings file section activates the log:
Adding only
is not enough.
So is it a documentation issue or a code issue?
Reproduction Steps
In the main branch of this repository https://github.com/fbouteruche/AWSSDKCallLogWebAppSample, you will find a sample that demonstrates that adding the above section will not output any logs in the console or in the Debug window.
In the branch https://github.com/fbouteruche/AWSSDKCallLogWebAppSample/tree/workaround-to-enable-local-log, you will find a sample of the proposed workaround.
Logs
This issue is about log.
Environment
SDK Version:
Package Version:
OS Info: Windows 10
Build Environment: Visual Studio 2019 16.8.2
Targeted .NET Platform: netcoreapp3.1
Resolution
This is a :bug: bug-report