Karl Stålenheim
Nov 12, 2025
visibility 1137
star star star star star
(3 votes)

Using Serilog in DXP

TL;DR Use Serilog.Sinks.Console for DXP apps — or skip Serilog entirely and rely on default logging.


It’s common during investigations that all the downloadable logs from the PaaS portal are empty.

In most cases, this happens because Serilog is used and configured to only write logs to files. While that works locally or in traditional hosting environments, it doesn’t play well with how Optimizely DXP handles logs.

What’s important to understand (maybe not clearly defined in documentation) is that the logs available in the PaaS Portal are App Service Console Logs and not file-based logs.

Implementing Serilog for Both Development and DXP

Below is an example of how the Program class can look. It uses a bootstrap logger during startup which ensures that logging is available even before the host is fully built, while still letting Serilog load its settings from configuration later on.

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .WriteTo.Console()
            .CreateBootstrapLogger();


        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureCmsDefaults()
            .UseSerilog((context, services, configuration) =>
            {
                configuration
                    .ReadFrom.Configuration(context.Configuration)
                    .ReadFrom.Services(services)
                    .Enrich.FromLogContext();
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

This setup requires the NuGet packages Serilog, Serilog.AspNetCore and Serilog.Sinks.Console are installed.

Configuration for Development

In development, you might want to see logs both in the console and written to a local file for troubleshooting.

Your appsettings.Development.json could look like this:

{
  "Serilog": {
    "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "EPiServer": "Information",
        "EPiServer.Commerce": "Warning",
        "Microsoft.Hosting.Lifetime": "Warning",
        "MySite.SomeNamespace": "Information"
      }
    },
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "File",
        "Args": {
          "path": "app_data/log.txt",
          "rollingInterval": "Day",
          "retainedFileCountLimit": 10
        }
      }
    ]
  }
}

This configuration assumes the package Serilog.Sinks.File is installed.

Configuration for DXP

Logs written to the console are captured as App Service Console Logs. These are the logs visible in the DXP portal.

For DXP, you can simplify and optimize Serilog by only using the console sink, optionally wrapped in an async sink which may or may not improve performance. This is how appsettings.<ENV>.json could look like:

{
  "Serilog": {
    "Using": ["Serilog.Sinks.Async", "Serilog.Sinks.Console"],
    "MinimumLevel": {
      "Default": "Warning",
      "Override": {
        "Microsoft": "Warning",
        "EPiServer": "Warning",
        "EPiServer.Commerce": "Warning",
        "Microsoft.Hosting.Lifetime": "Information",
        "MySite.SomeNamespace": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "Async",
        "Args": {
          "configure": [
            { "Name": "Console" }
          ]
        }
      }
    ]
  }
}

The configuration assumes that Serilog.Sinks.Async and Serilog.Sinks.Console are installed.


With this setup, you can enjoy all the benefits of Serilog’s structured logging while ensuring that logs are still captured correctly in Optimizely DXP.

Nov 12, 2025

Comments

huseyinerdinc
huseyinerdinc Nov 12, 2025 01:23 PM

Nice tips, thank you. Does this prevent the wrapping of logs into the the following json? Can we use CompactJsonFormatter to define our own log structure or will the output always be wrapped in resultDescription?

 

Karl Stålenheim
Karl Stålenheim Nov 12, 2025 01:51 PM

I believe that this format corresponds to the columns in AppServiceAppLogs table and something that is set outside the app. So, the logs in the PaaS portal will be in this fixed format.

error Please login to comment.
Latest blogs
Architecting an Enterprise-Grade Development Pipeline in Optimizely SaaS CMS

Most enterprise teams show up to Optimizely SaaS CMS with a clear roadmap for their release pipeline: DEV → QA → Stage → Prod. Four logical...

Vipin Banka | Jul 12, 2026

Bynder DAM Connector for Optimizely SaaS CMS: Improved Metadata Property Synchronization

While working with the Bynder DAM Connector for Optimizely SaaS CMS , one of the key areas I explored was how Bynder asset metadata is synchronized...

Vipin Banka | Jul 11, 2026

Optimizely DXP: Every Supported Culture, One Searchable Page

Quick one for anyone building multi-language sites on Optimizely DXP. I put together a reference tool listing all 806 supported cultures. More...

Adnan Zameer | Jul 10, 2026 |

A day in the life of an Optimizely OMVP: London Meetup 2026

On 2nd July 2026 the Optimizely London Developer Meetup returned to The Lightwell, and the running theme across the evening was less about individu...

Graham Carr | Jul 10, 2026

Optimizely’s Summer ’26 Roadmap: The CMS Is Starting to Look Less Like a Publishing Tool and More Like Marketing Infrastructure

Optimizely’s Summer ’26 Product Roadmap event was not just a list of product updates. At least, that is not the part I found most interesting. The...

Augusto Davalos | Jul 9, 2026

Optimizely Content JS SDK v2.1.0 — What's New and Why It Matters

  v2.1.0 of the Optimizely Content JS SDK and CLI landed on July 7, 2026. This is a substantial release bringing a wave of capabilities for...

Vipin Banka | Jul 8, 2026