2

I'm using WebJobsStartup with my azure function. In Startup.cs file , I'm loading say abc.dll from my another project using reflection and invoking it's main method. I want to get logs from this called method(abc.dll) along with HttpTrigger function.

In main method of abc.dll, I'm using ILogger to log messages and same with my azure function.

When I deploy this function to azure (Azure functions), I'm able to see logs related to azure function only and not of abc.dll (called method). I have checked that abc.dll is getting loaded (by calling logging on webpage)

I've tried application insights and live metrics, updated host.json as various options provided at in documentation of Azure links below:

              "fileLoggingMode": "debugOnly",
               "logLevel": {
               "Function.HttpTriggerAzureCSharp1":"Information",
               "Host.Results": "Error",
               "Host.Aggregator": "Trace",
               "default": "Information"
              },

which seems not working.

Please suggest options to show logs of abc.dll (called method) with azure function.

I am using azure funtions with below details:

  • OS : Linux
  • Plan : consumption
  • Platform : .net-core
  • Dev Env:Visual Studio Code
  • Language : C#

I have already tried this this2

Dipti Sheth
  • 159
  • 1
  • 2
  • 11
  • How is the Illogger inside abc.dll injected? If it is not hooked up to the DI configuration of the function it might not work. – Peter Bons Jan 14 '21 at 09:42
  • I just created new instance of LoggerFactory and used ILogger. How to hook it to DI configuration of function to make it work ? – Dipti Sheth Jan 14 '21 at 10:06
  • 1
    If abc.dll contains some classes you want to use, you should [register them](https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#register-services) in the DI configuration of the function. Then the Ilogger will be injected – Peter Bons Jan 14 '21 at 10:29
  • ok..will try it out . Thanks for the quick reply. It would be good if you can provide some working example. – Dipti Sheth Jan 14 '21 at 11:38

1 Answers1

0

As Peter mentioned in comments, you can register them in DI configuration of the function. enter image description here

Here is a sample for your reference, you can refer to it to know how to develop the code of your service and log provider. enter image description here

enter image description here

Hury Shen
  • 14,948
  • 1
  • 9
  • 18