• Guides
  • Api Reference
  • FAQ
  • Guides
  • Cross Cutting Concerns
  • Logging
Show / Hide Table of Contents
  • Overview
    • Introduction
    • Getting Started
    • Philosophy
    • FAQ
    • Upgrading to 1.0
  • Triggers
    • HTTP Triggers
      • Overview
      • Routing
      • Responses
      • Authorization
      • Claims Mapping
      • Headers
      • Swagger / OpenAPI
    • Service Bus Triggers
      • Queues
      • Topic and Subscriptions
      • Message Properties
      • Message Sessions
    • Cosmos DB
      • Overview
      • Error Handling
    • SignalR
    • Timer Triggers
    • Azure Storage Triggers
      • Queues
      • Blobs
    • Event Hub Triggers
  • Output Bindings
  • Cross Cutting Concerns
    • Connection Strings
    • IoC Containers
    • Logging
    • Trigger Contexts
    • Validation
    • Serialization
    • Suggested Solution Structure
  • Contributing
    • Compiling
    • Debugging

Logging

Function Monkey wires up the Azure Functions provided ILogger in the dependency injector.

To use it simply inject an ILogger into your handlers or services.

If you add logging into your application via the AddLogging extension method for IServiceCollection that will replace the Azure Functions logger and you will need to ensure it outputs to targets as you require.

Handler using an injected logger:

public class GetEchoQueryHandler : ICommandHandler<GetEchoQuery>
    {
        private readonly ILogger<GetEchoQueryHandler> logger;

        public GetEchoQueryHandler(ILogger<GetEchoQueryHandler> logger)
        {
            this.logger = logger;
        }

        public Task ExecuteAsync(GetEchoQuery command)
        {
            this.logger.Log(LogLevel.Information, "echo");
            return Task.CompletedTask;
        }
     }

FunctionAppConfiguration logging setup:

 builder
                .Setup((serviceCollection, commandRegistry) =>
                {
                    ....
                    serviceCollection.AddLogging(c =>
                    {
                        c.AddConsole();
                        c.AddDebug();
                    });
  • Improve this Doc
  • 0 Comments
Back to top Copyright © 2018 James Randall