有在Kibana没有登录时的API泊坞窗下运行(There are no logs in Kiban

2019-09-27 16:45发布

美好时光。 我想看看在Kibana我的日志。 为了看到他们,我用Serilog和运行我的应用程序,Elasticsearch和Kibana在泊坞窗。 不幸的是日志不会出现在Kibana。 我也无法找到lett-api kibana指数。

还有就是我的Program文件:

public class Program
    {
        public static int Main(string[] args)
        {
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-GB");
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .Enrich.FromLogContext()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.WithProperty("app", "Lett.Api")
                .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(
                    new Uri("http://elasticsearch:9200"))
                {
                    AutoRegisterTemplate = true,
                    IndexFormat = "lett-api",
                    FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
                    EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
                                       EmitEventFailureHandling.WriteToFailureSink |
                                       EmitEventFailureHandling.RaiseCallback,
                    FailureSink = new FileSink("./failures.txt", new JsonFormatter(), null)
                })
                .CreateLogger();


            try
            {
                BuildWebHost(args).Run();
                return 0;
            }
            finally
            {
                Log.CloseAndFlush();
            }

        }

        private static IWebHost BuildWebHost(string[] args)
        {
            return new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseSerilog()
                .ConfigureAppConfiguration((ctx, builder) =>
                {
                    builder
                        .SetBasePath(ctx.HostingEnvironment.ContentRootPath)
                        .AddJsonFile("appsettings.json", true)
                        .AddEnvironmentVariables("Docker:");
                })
                .UseStartup<Startup>()
                .Build();
        }
    }

我的docker-compose文件:

 version: '3.7'

services: 
  postgres:
    container_name: postgresql
    image: postgres:alpine
    environment:
      - POSTGRES_PASSWORD=12345
      - POSTGRES_USER=postgres
    ports:
      - 5432:5432

  api:
    container_name: lett-api
    image: lett:latest
    restart: on-failure
    build:
      context: .
      dockerfile: ./Lett.Api.Dockerfile
    depends_on:
      - postgres
      - elasticsearch
    ports:
      - 5000:80
    environment:
      Docker:ConnectionString: "Host=postgres;Username=postgres;Password=12345;Database=Lett"

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.zen.minimum_master_nodes=1
      - discovery.type=single-node
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - "9200:9200"
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    networks:
      - docker-network

  kibana:
    image: docker.elastic.co/kibana/kibana:7.2.0
    container_name: kibana
    depends_on:
      - elasticsearch
    environment:
      elasticsearch.url: "http://elasticsearch:9200"
      elasticsearch.hosts: "http://elasticsearch:9200"
      xpack.security.enabled: "false"
      xpack.monitoring.enabled: "false"
      xpack.ml.enabled: "false"
      xpack.graph.enabled: "false"
      xpack.reporting.enabled: "false"
      xpack.grokdebugger.enabled: "false"
    ports:
      - "5601:5601"
    networks:
      - docker-network

volumes:
  elasticsearch-data:
    driver: local

networks:
  docker-network:
    driver: bridge

但是当我在本地运行我的应用程序(使用ElasticsearchUri = http://localhost:9200lett-api指数出现并记录了。

有谁知道热点的问题是什么?

谢谢!

UPDATE我检查泊坞窗输出,发现如下:

lett-api         | Unable to submit event {HostingRequestStartingLog:l}
lett-api         | Unable to submit event {HostingRequestFinishedLog:l}
lett-api         | Unable to submit event {HostingRequestStartingLog:l}
lett-api         | Unable to submit event {HostingRequestFinishedLog:l}
lett-api         | Unable to submit event {HostingRequestStartingLog:l}
lett-api         | Unable to submit event CORS policy execution successful.
lett-api         | Unable to submit event Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName}).
lett-api         | Unable to submit event Executing action method {ActionName} - Validation state: {ValidationState}
lett-api         | Unable to submit event Executed action method {ActionName}, returned result {ActionResult} in {ElapsedMilliseconds}ms.
lett-api         | Unable to submit event Executing ObjectResult, writing value of type '{Type}'.
lett-api         | Unable to submit event Executed action {ActionName} in {ElapsedMilliseconds}ms
lett-api         | Unable to submit event {HostingRequestFinishedLog:l}

Answer 1:

日志未写入kibana因为lett-api中没有docker-network

有一个正确的docker-compose文件:

version: '3.7'

services: 
  postgres:
    container_name: postgresql
    image: postgres:alpine
    environment:
      - POSTGRES_PASSWORD=12345
      - POSTGRES_USER=postgres
    ports:
      - 5432:5432

  api:
    container_name: lett-api
    image: lett:latest
    restart: on-failure
    build:
      context: .
      dockerfile: ./Lett.Api.Dockerfile
    depends_on:
      - postgres
      - elasticsearch
    ports:
      - 5000:80
    environment:
      Docker:ConnectionString: "Host=postgres;Username=postgres;Password=12345;Database=Lett"
    networks:
      - docker-network

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.zen.minimum_master_nodes=1
      - discovery.type=single-node
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - "9200:9200"
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    networks:
      - docker-network

  kibana:
    image: docker.elastic.co/kibana/kibana:7.2.0
    container_name: kibana
    depends_on:
      - elasticsearch
    environment:
      elasticsearch.url: "http://elasticsearch:9200"
      elasticsearch.hosts: "http://elasticsearch:9200"
      xpack.security.enabled: "false"
      xpack.monitoring.enabled: "false"
      xpack.ml.enabled: "false"
      xpack.graph.enabled: "false"
      xpack.reporting.enabled: "false"
      xpack.grokdebugger.enabled: "false"
    ports:
      - "5601:5601"
    networks:
      - docker-network

volumes:
  elasticsearch-data:
    driver: local

networks:
  docker-network:
    driver: bridge



文章来源: There are no logs in Kibana when API is run under docker