---
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."
---

:ReleaseNotes(https://portal.nodinite.com/marketplace/15):

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

:new2.0.35:

>[!INFO]
>This document applies to Nodinite Serilog sinks version >= 2.0.35 and demonstrates how to use the [Microsoft.Extensions.Logging.ILogger](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger)<sup>:fa-arrow-up-right-from-square:</sup> interface for logging in Azure Functions (.NET 8+ with the [isolated worker model](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-differences)<sup>:fa-arrow-up-right-from-square:</sup>). This approach is ideal for customers with existing codebases, as it allows you to add :Nodinite: logging with minimal code changes.

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

:Nodinite:'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 :Nodinite:'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 :Nodinite:'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>:fa-arrow-up-right-from-square:</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 :Nodinite: logging with [Microsoft.Extensions.Logging.ILogger](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger)<sup>:fa-arrow-up-right-from-square:</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)
  * [:fa-hand-point-right: Next Steps](#fa-hand-point-right-next-steps)
  * [:fa-link-horizontal: Related Topics](#fa-link-horizontal-related-topics)

>[!INFO]
>The **Settings** section is documented on a shared page. Read more at ['Settings Section (appsettings.json)'][Serilog - Shared Section]

## 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>:fa-arrow-up-right-from-square:</sup> (if you use the Blob sink, choose any other :Nodinite: 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)

>[!IMPORTANT]
>**Structured logging requires OriginalMessageType for business intelligence** - When using semantic logging with named properties like `{OriginalMessageType}`, this field determines which [Search Field Expressions][] extract business data from your logs. Without proper [Message Types][], features like [Non-Events Monitoring][], [Business Process Modeling (BPM)][BPM], and business-data searches in [Log Views][] won't function. The `OriginalMessageType` property must be included as a semantic property in every LogInformation/LogError call that you want to be searchable by business data. **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.**

```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);
        }
    }
}
```

___

## :fa-hand-point-right: Next Steps

:fa-file: [Configure Message Types][Message Types] - Essential for semantic logging to extract business data from structured properties  

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

## :fa-link-horizontal: Related Topics

:fa-hard-drive: [Logging][]  
:fa-bolt: [Log Events][Log Event]  
:fa-file-code: [JSON Log Event][]  
:fa-truck-pickup: [Pickup Log Events Service Logging Agent][Pickup Service]  
:fa-file: [Message Types][] - Critical for mapping semantic properties to searchable business data  
:fa-magnifying-glass-plus: [Search Fields][] - Extract business data from logged messages  
:fa-magnifying-glass-plus: [Search Field Expressions][] - Define extraction patterns for structured logging properties  
:fa-table-list: [Log Views][] - Search logged data by business identifiers  
:fa-stopwatch: [Non-Events Monitoring][] - Track message volumes and patterns  
:fa-project-diagram: [Business Process Modeling (BPM)][BPM] - End-to-end transaction correlation  
:fa-coins: [Reduce Azure Functions Logging Costs][] - Lower the Azure cost of logging Azure Functions  
:fa-coins: [Azure Costs for Blob Storage and Event Hub][] - What staging log events in Azure costs  
:fa-clock: [Reduce Azure Logic Apps Run History Retention to Lower TCO][] - The same approach for Logic Apps  
:fa-cloud-arrow-down: [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]:{ndr}/Logging%20and%20Monitoring/Custom%20Logging/Troubleshooting/Azure%20Costs%20for%20Blob%20Storage%20and%20Event%20Hub.md
[BPM]:{ndr}/Repository%20Model/BPMs/Overview.md
[JSON Log Event]:{ndr}/Core%20Services/Log%20Event/Features/JSON%20Log%20Event.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Logging]:nodiniteDoc:/Logging
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[Non-Events Monitoring]:{ndr}/Logging%20and%20Monitoring/Non-Events/Overview.md
[Pickup Service]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Overview.md
[Reduce Azure API Management Logging Costs]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Troubleshooting/Reduce%20Azure%20API%20Management%20Logging%20Costs.md
[Reduce Azure Functions Logging Costs]:{ndr}/Logging%20and%20Monitoring/Serilog/Troubleshooting/Reduce%20Azure%20Functions%20Logging%20Costs.md
[Reduce Azure Logic Apps Run History Retention to Lower TCO]:{ndr}/Logging%20and%20Monitoring/Azure%20Logic%20Apps/Troubleshooting/Reduce%20Azure%20Logic%20Apps%20Run%20History%20Retention%20to%20Lower%20TCO.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[Serilog - Blob Storage]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Blob%20Storage.md
[Serilog - Event Hub]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Event%20Hub.md
[Serilog - File]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/File.md
[Serilog - LogAPI]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Log%20API.md
[Serilog - Logger]:{ndr}/Logging%20and%20Monitoring/Serilog/How%20To%20Start%20Logging%20With%20Serilog.md
[Serilog - Service Bus]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/ServiceBus.md
[Serilog - Shared Section]:{ndr}/Logging%20and%20Monitoring/Serilog/Settings%20Section.md