---
title: How To Start Logging With ILogger in Azure Functions using Nodinite Serilog Sinks
description: "Learn how to configure Nodinite logging for Azure Functions using the ILogger interface. This guide demonstrates how to leverage Nodinite's Serilog sinks with minimal code changes, enabling seamless integration and advanced logging for modern cloud solutions."
---

<a class="nodinite-release-notes" href="https://portal.nodinite.com/marketplace/15" data-url="https://portal.nodinite.com/marketplace/15"><i class="fal fa-fw fa-file-alt" aria-hidden="true"></i> Release Notes</a>

# How To Start Logging With Microsoft.Extensions.Logging.ILogger in Azure Functions

<sup><span class="nodinite-new-badge">New 2.0.35</span></sup>

<aside aria-label="Info" class="nodinite-note nodinite-note--info">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-square-info"></i> Info</p>
<div class="nodinite-note__content"><p>This document applies to Nodinite Serilog sinks version &gt;= 2.0.35 and demonstrates how to use the <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger">Microsoft.Extensions.Logging.ILogger</a><sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> interface for logging in Azure Functions (.NET 8+ with the <a href="https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-differences">isolated worker model</a><sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>). This approach is ideal for customers with existing codebases, as it allows you to add <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> logging with minimal code changes.</p></div>
</aside>

If you want to log using the "native" Serilog **Logger**, see ['How To Start Logging With Serilog'][Serilog - Logger].

<span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>'s logging solution empowers system integration experts to achieve robust, structured, and centralized logging with minimal friction. By leveraging the standard `ILogger` interface, you can seamlessly integrate <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>'s advanced logging capabilities into your Azure Functions or any .NET application. This method is highly recommended for both new and existing projects, as it enables you to benefit from <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>'s unique selling points:

* Integrate effortlessly with existing codebases—just update configuration and dependencies  
* Centralize and search logs for compliance, troubleshooting, and monitoring  
* Support multiple sinks ([Blob][Serilog - Blob Storage], [Event Hub][Serilog - Event Hub], [File][Serilog - File], [Log API][Serilog - LogAPI], [Service Bus][Serilog - Service Bus], etc.)  
* Add advanced metadata and correlation for end-to-end traceability  
* Ensure full compatibility with DevOps and automation pipelines  
* [Structured logging](https://github.com/NLog/NLog/wiki/How-to-use-structured-logging)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>: Use structured log messages with named properties to enable powerful filtering, analytics, and machine-readable insights. Semantic logging makes it easy to correlate events, extract business context, and automate monitoring or alerting. This approach is especially valuable for large-scale, distributed, or regulated environments where traceability and data mining are essential.  

Below you'll find a step-by-step example of how to configure and use <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> logging with [Microsoft.Extensions.Logging.ILogger](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> in Azure Functions using the isolated worker model.

There are three different settings examples available (appsettings.json); the rest of the code examples below are the same regardless of which method you choose.  

* [How To Start Logging With Microsoft.Extensions.Logging.ILogger in Azure Functions](#how-to-start-logging-with-microsoft.extensions.logging.ilogger-in-azure-functions)
  * [Required NuGet packages](#required-nuget-packages)
  * [Dependencies in Project (.csproj)](#dependencies-in-project.csproj)
  * [Startup file (Program.cs)](#startup-file-program.cs)
  * [Log (Function.cs)](#log-function.cs)
  * [<i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps](#fa-hand-point-right-next-steps)
  * [<i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics](#fa-link-horizontal-related-topics)

<aside aria-label="Info" class="nodinite-note nodinite-note--info">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-square-info"></i> Info</p>
<div class="nodinite-note__content"><p>The <strong>Settings</strong> section is documented on a shared page. Read more at <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/settings-section/">'Settings Section (appsettings.json)'</a></p></div>
</aside>

## Required NuGet packages

To enable Serilog Logging, add the required NuGet packages to your project. You can do this using the NuGet Package Manager in Visual Studio or by editing the .csproj file directly:

* [Nodinite.Serilog.AzureBlobStorageSink](https://www.nuget.org/packages/Nodinite.Serilog.AzureBlobStorageSink/)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> (if you use the Blob sink, choose any other <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> sink you like)  
* Serilog.AspNetCore  

## Dependencies in Project (.csproj)

Update the **version** when you update the NuGet packages. The versions below are examples. Always update to the latest version.

``` xml
    <ItemGroup>
        ...
        <PackageReference Include="Nodinite.Serilog.AzureBlobStorageSink" Version="2.0.36" />
        <PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
  </ItemGroup>
```

## Startup file (Program.cs)

```csharp
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Settings.Configuration;

var builder = Host.CreateDefaultBuilder(args)
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        // Add any additional services here
    })
    .ConfigureAppConfiguration(config =>
    {
        config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
        config.AddEnvironmentVariables(); // Optional
    })
    .UseSerilog((context, configuration) =>
    {
        configuration.ReadFrom.Configuration(context.Configuration,
            new ConfigurationReaderOptions
            {
                SectionName = "Serilog",
            });
    });

// Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4.
// builder.Services
//     .AddApplicationInsightsTelemetryWorkerService()
//     .ConfigureFunctionsApplicationInsights();

builder.Build().Run();
```

## Log (Function.cs)

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>Structured logging requires OriginalMessageType for business intelligence</strong> - When using semantic logging with named properties like <code>{OriginalMessageType}</code>, this field determines which <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/">Search Field Expressions</a> extract business data from your logs. Without proper <a href="https://docs.nodinite.com/repository-model/message-types/overview/">Message Types</a>, features like <a href="https://docs.nodinite.com/logging-and-monitoring/non-events/overview/">Non-Events Monitoring</a>, <a href="https://docs.nodinite.com/repository-model/bpms/overview/">Business Process Modeling (BPM)</a>, and business-data searches in <a href="https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/">Log Views</a> won't function. The <code>OriginalMessageType</code> property must be included as a semantic property in every LogInformation/LogError call that you want to be searchable by business data. <strong>Plan your Message Types before implementing structured logging - they define how Nodinite extracts Order Numbers, Customer IDs, Invoice amounts, and other business identifiers from your logged properties.</strong></p></div>
</aside>

```csharp
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace IsolatedWorkerExample.Functions
{
    public class MyFunction
    {
        private readonly ILogger<Function1> _logger;

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

        [Function("Function1")]
        public async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route=null)] HttpRequest req)
        {
            _logger.LogInformation("Function1");

            string name = req.Query["name"];

            var value = req.Headers.ContainsKey("clientTrackingId");

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;
            
            var body = JsonConvert.SerializeObject(new { Id = 1 });
            
            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            if (req.Headers.ContainsKey("x-ms-client-tracking-id"))
            {
                Microsoft.Extensions.Primitives.StringValues id;
                req.Headers.TryGetValue("x-ms-client-tracking-id", out id);

                if (string.IsNullOrWhiteSpace(id[0]))
                {
                    _logger.LogInformation("{LogText} {ApplicationInterchangeId} {InputMessage} {OriginalMessageType} {Color}", "Hello from Function (without interchange id)", Guid.NewGuid(), body, "TestMessage#1.0", "Blue");
                }
                else
                {
                    _logger.LogInformation("{LogText} {ApplicationInterchangeId} {Body} {OriginalMessageType} {Color}", "Hello from Function", id[0], body, "TestMessage#1.0", "Blue");
                }
            }

            return new OkObjectResult(responseMessage);
        }
    }
}
```

___

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

<i class="fal fa-file" aria-hidden="true"></i> [Configure Message Types][Message Types] - Essential for semantic logging to extract business data from structured properties  

❔['How To Start Logging With Serilog'][Serilog - Logger]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

<i class="fal fa-hard-drive" aria-hidden="true"></i> [Logging][]  
<i class="fal fa-bolt" aria-hidden="true"></i> [Log Events][Log Event]  
<i class="fal fa-file-code" aria-hidden="true"></i> [JSON Log Event][]  
<i class="fal fa-truck-pickup" aria-hidden="true"></i> [Pickup Log Events Service Logging Agent][Pickup Service]  
<i class="fal fa-file" aria-hidden="true"></i> [Message Types][] - Critical for mapping semantic properties to searchable business data  
<i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Fields][] - Extract business data from logged messages  
<i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Field Expressions][] - Define extraction patterns for structured logging properties  
<i class="fal fa-table-list" aria-hidden="true"></i> [Log Views][] - Search logged data by business identifiers  
<i class="fal fa-stopwatch" aria-hidden="true"></i> [Non-Events Monitoring][] - Track message volumes and patterns  
<i class="fal fa-project-diagram" aria-hidden="true"></i> [Business Process Modeling (BPM)][BPM] - End-to-end transaction correlation  
<i class="fal fa-coins" aria-hidden="true"></i> [Reduce Azure Functions Logging Costs][] - Lower the Azure cost of logging Azure Functions  
<i class="fal fa-coins" aria-hidden="true"></i> [Azure Costs for Blob Storage and Event Hub][] - What staging log events in Azure costs  
<i class="fal fa-clock" aria-hidden="true"></i> [Reduce Azure Logic Apps Run History Retention to Lower TCO][] - The same approach for Logic Apps  
<i class="fal fa-cloud-arrow-down" aria-hidden="true"></i> [Reduce Azure API Management Logging Costs][] - The same approach for API Management  

* [Serilog - Blob Storage][]  
* [Serilog - Event Hub][]  
* [Serilog - File][]  
* [Serilog - LogAPI][]  
* [Serilog - Service Bus][]  

[Azure Costs for Blob Storage and Event Hub]:https://docs.nodinite.com/logging-and-monitoring/custom-logging/troubleshooting/azure-costs-for-blob-storage-and-event-hub/
[BPM]:https://docs.nodinite.com/repository-model/bpms/overview/
[JSON Log Event]:https://docs.nodinite.com/core-services/log-event/features/json-log-event/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Logging]:https://docs.nodinite.com/logging/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[Non-Events Monitoring]:https://docs.nodinite.com/logging-and-monitoring/non-events/overview/
[Pickup Service]:https://docs.nodinite.com/logging-and-monitoring/pickup-logevents-service/overview/
[Reduce Azure API Management Logging Costs]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/troubleshooting/reduce-azure-api-management-logging-costs/
[Reduce Azure Functions Logging Costs]:https://docs.nodinite.com/logging-and-monitoring/serilog/troubleshooting/reduce-azure-functions-logging-costs/
[Reduce Azure Logic Apps Run History Retention to Lower TCO]:https://docs.nodinite.com/logging-and-monitoring/azure-logic-apps/troubleshooting/reduce-azure-logic-apps-run-history-retention-to-lower-tco/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[Serilog - Blob Storage]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/blob-storage/
[Serilog - Event Hub]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/event-hub/
[Serilog - File]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/file/
[Serilog - LogAPI]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/log-api/
[Serilog - Logger]:https://docs.nodinite.com/logging-and-monitoring/serilog/how-to-start-logging-with-serilog/
[Serilog - Service Bus]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/servicebus/
[Serilog - Shared Section]:https://docs.nodinite.com/logging-and-monitoring/serilog/settings-section/