RockFish
RockFish

Reputation: 31

Use Nlog for CloudwatchLog

I need a detailed/step by step guide for this. I have read the brief guide (example here) and downloaded the sample code, but I still can't figure out how to use Nlog to log to CloudWatch.

  1. As soon as I put in the target in NLog.config, , Intellisense tells me that the name, type, logGroup, region attributes are not declared
  2. What NuGet packages do I need to install? From what I can tell, Nlog and AWSSDK.CloudWatchLogs only. Am I right?
  3. Do I still need to perform the configuration with code, or is just setting the NLog.config file enough? I get the feeling that I will to do both.

(Edit : 4. Where do I specify the AccessKey/SecretKey/credential, and the logStream? Figured out the stored credential and logStream cannot be changed yet. It always uses the first one)

When I tried to run an example code to write the log, I get the error that the AWSTarget is not found/defined. I have spent over a day on trying to figure this out, and I don't think it is that difficult so I must be doing something wrong. Please help! Thank you.

Upvotes: 3

Views: 3361

Answers (3)

Rolf Kristensen
Rolf Kristensen

Reputation: 19857

Updated the AWS guide to include:

  <extensions>
    <add assembly="NLog.AWS.Logger" />
  </extensions>

Important puzzle piece when using NLog on NetCore-platform

Upvotes: 0

vtortola
vtortola

Reputation: 35905

I just ran into this issue, and the problem is that some dependencies are missing because they are not specified as dependencies. If you use the programmatic example and dig deeper, you will see some exceptions regarding types that are not available.

You need will the packages:

  • AWS.Logger.Core
  • AWSSDK.CloudWatch
  • AWSSDK.CloudWatchLogs
  • NLog
  • NLog.AWS.Logger

Upvotes: 4

Julian
Julian

Reputation: 36710

I have no experience with AWS.Logger.Nlog, but the most rules for all these packages are the same.

As soon as I put in the target in NLog.config, , Intellisense tells me that the name, type, logGroup, region attributes are not declared

You can ignore this. Most custom targets don't provide a XSD file.

What NuGet packages do I need to install? From what I can tell, Nlog and AWSSDK.CloudWatchLogs only. Am I right?

As there is no NuGet Package dependency between AWS.Logger.NLog and NLog, I would expect AWS.Logger.NLog and NLog. Because AWS.Logger.NLog is updated recently, I think it works well with NLog 4. To be sure, I would recommend to ask this on their Github repository.

Do I still need to perform the configuration with code, or is just setting the NLog.config file enough? I get the feeling that I will to do both.

In general all NLog targets could be configured by code or (xml) config. You can also combine both, but that could be tricky - that's another topic.

Where do I specify the AccessKey/SecretKey/credential, and the logStream?

That should you as on their Github repository.

Upvotes: 0

Related Questions