Ramprasad
Ramprasad

Reputation: 326

Using NLog in Azure Functions

I have an Azure functions which refers the custom dll which we have written to access the graph api calls. In the dll, we also have a NLog logger facility which helps to log the details.

Some thing like we have a NLog nuget package referred and we have a ILoggingService and LoggingService which implements the same and inside the LoggingService we have written like:

Logger logger = LogManager.GetCurrentClassLogger();

Now I want my Azure function to use this logger and log the details that we are doing it in the dll as well while running the Azure function.

Upvotes: 2

Views: 4694

Answers (2)

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

If you want to redirect the NLog output from the custom dll into the Azure-function-console.

Then I guess you can do one of 2 things:

  • Use the MicrosoftILogger Target to redirect the NLog output to ILogger for the Azure-function.
  • Configure NLog to write to the Console target and see if the Azure-function will automatically capture this output.

Both cases probably requires you to setup NLog Configuration using the Config-API.

See also: NLog cloud logging with Azure function

Upvotes: 2

ahmelsayed
ahmelsayed

Reputation: 7392

You can register an ILoggerProvider in the DI system, then use ILogger from your function.

Docs: https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#logging-services

Upvotes: 1

Related Questions