Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not view logs of ASP NET Core Container

Hello i have the following problem:

I have a ASP .NET Core server that is docker-ized and runs in a container with docker-compose.I send requests to my server via postman and i get 500-internal server error.

I have tried:

  • docker attach myserver and i get nothing in the console.
  • docker logs myserver i will get only the initial log (the startup).
  • telnet hostname port and it seems it works to connect but i do not know how to create the request.

How can i get my hands on the console of my ASP .NET Core server?

docker-compose

version: '3.3'
services:
    db:
      image: redis:4.0.5-alpine
      container_name: redis0

      networks: 
        - redis-net
      ports:
        - 6381:6379

    backend:
      image: server
      container_name: server0
      build: ./Server
      command: ["dotnet","Server.dll"]
      depends_on:
        - db
      ports:
        - 9400:9300
      networks:
        - redis-net

networks:
    redis-net:

dockerfile (for server)

FROM microsoft/dotnet:2.1-aspnetcore-runtime 
WORKDIR /app
COPY ./publish /app
EXPOSE 9300

Startup.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
            string port="9300";
            var builder = new WebHostBuilder();
            builder.UseStartup<Startup>();
            var url =$"http://0.0.0.0:{port.ToString()}/";//Address.Default.ToUrl();
            Debug.WriteLine(url);
            builder.UseKestrel().UseUrls(url);
            return builder;

        }
like image 963
Bercovici Adrian Avatar asked Dec 11 '18 14:12

Bercovici Adrian


People also ask

How to configure logging in ASP NET Core?

Configure logging. Logging configuration is commonly provided by the Logging section of appsettings. ... Test the settings when using an app created with the ASP.NET Core web application templates. The dotnet run command must be run in the project directory after using set.

How does Docker logging relate to ASP NET Core logging?

This post explores the building blocks upon which Docker logging is built, and how it relates to ASP.NET Core’s logging. Docker determines the destination for log messages via a logging driver.

Where are logs stored in ASP NET?

Logging providers store logs, except for the Console provider which displays logs. For example, the Azure Application Insights provider stores logs in Azure Application Insights. Multiple providers can be enabled. The default ASP.NET Core web app templates: Use the Generic Host.

What is serilog logger in ASP NET Core?

In the following example, a Serilog logger is used to log in CreateHostBuilder. AddSerilog uses the static configuration specified in Log.Logger: Constructor injection of a logger into Startup works in earlier versions of ASP.NET Core because a separate DI container is created for the Web Host.


1 Answers

  • Configure your .net core app to print logs to the console

    E.g. Console.WriteLine("Some application log");

  • Rebuild & run the containers

    docker-compose build

    docker-compose up

  • Get the container-id for the running server container using

    docker ps

  • Run this in another command window to follow the logs

    docker logs --follow <container-id>

  • Run this to get into the container's bash shell

    docker exec -it <container-id> bash

like image 54
hellosri Avatar answered Sep 30 '22 11:09

hellosri