`_logger.LogInformation` not printing the message to the console in .NET 6

krishna572 876 Reputation points
2023-03-23T07:57:10.54+00:00

Not getting the logger information in the console output - Service Bus Trigger

  1. Created Service Bus Namespace - 1 topic - 1 subscription
  2. Created logic app to send the message for the topic subscription with the content as "Message with Guid()"
  3. After running the function, run the logic app workflow.
  4. Logic app workflow is running successfully with the message producing and that message is also coming to the function app code logger info line but not printing on the console.

Running Locally

host.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

Function.cs

public class Function1
    {
        private readonly ILogger<Function1> _logger;

        public Function1(ILogger<Function1> log)
        {
            _logger = log;
        }

        [FunctionName("Function1")]
        public void Run([ServiceBusTrigger("demotopic", "demosubsn", Connection = "SBConnection")]string mySbMsg)
        {
            _logger.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
        }
    }

Output:

Functions:

        Function1: serviceBusTrigger

For detailed output, run func with --verbose flag.
[2023-03-23T07:40:28.225Z] Host lock lease acquired by instance ID '<Some_Id>'.
[2023-03-23T07:40:31.148Z] Executing 'Function1' (Reason='(null)', Id=
<Some_Id>)
[2023-03-23T07:40:31.150Z] Trigger Details: MessageId: 
<Some_Id>, SequenceNumber: 7, DeliveryCount: 1, EnqueuedTimeUtc: 2023-03-23T07:40:31.4090000Z, LockedUntilUtc: 2023-03-23T07:41:31.4560000Z, SessionId: (null)
[2023-03-23T07:40:40.968Z] Executed 'Function1' (Succeeded, Id=
<Some_Id>, Duration=9865ms)

I'm not getting the message that is

C# ServiceBus topic trigger function processed message: {mySbMsg}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,211 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. krishna572 876 Reputation points
    2023-03-25T06:13:53.14+00:00

    Resolution:

    I'm missing the ILogger Class in the Function declaration.

    public void Run([ServiceBusTrigger("demotopic", "demosubsn", Connection = "SBConnection")]string mySbMsg, ILogger _logger)
    
    1 person found this answer helpful.