How can I use same Seq Docker instance for multiple ASP.NET Core Web API projects

I have an ASP.NET Core Web API project where I am using Serilog with Seq and I have the Seq server hosted inside a docker container. Now, this works, there is nothing wrong with this. However, when I want to create more .NET Core projects, I don’t want to create more Docker instances for SEQ. Is there a way I can use the same Docker instance of SEQ for multiple ASP.NET Core Web API projects?

This is my current appsettings.json file

{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.Seq"
    ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Sixteen, Serilog.Sinks.Console"
        }
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "http://localhost:5341"
        }
      }
    ],
    "Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"]
  },
}

And I am using that config like the following in the program.cs file

builder.Host.UseSerilog((context, loggerConfig) =>
    loggerConfig.ReadFrom.Configuration(context.Configuration));

Any reference to the docs would be helpful, too, I can’t find anything in the documentation.

  • Are you getting any error ?

    – 

So, I found a solution, it turned out if you want to use multiple projects with Seq, you can create API keys for each project, let’s say I have two projects called QMS(Quality Management System) and TLS(Traffic Light System), now, I want to to include logs for both of this projects to one single SEQ project. To do this, go to
Settings -> API Keys -> Add API Key.

Here, create a title like KDS QMS API Key, and in the Attached properties , attach Application = QMS
and, create another title like KDS TLS API Key, and in the Attached properties , attach Application = TLS

Now, in the main dashboard you can type Application=”QMS” to see QMS project logs, and Application=”TLS” to TLS project logs.

Learn more from Official Docs

One more thing, if you are running both QMS and TLS project inside docker containers, then you have to make sure the SEQ docker instance is accessible from inside those docker containers.

Also, feel free you to share a better solution if you found any. Happy Coding!

Leave a Comment