zoukankan      html  css  js  c++  java
  • EL+Serilog日志

    简介

    Elasticsearch 是一个实时的分布式搜索分析引擎,它能让你以前所未有的速度和规模,去探索你的数据。 它被用作全文检索、结构化搜索、分析以及这三个功能的组合:

    安装

    Elasticsearch安装

    {
      "name" : "Tom Foster",
      "cluster_name" : "elasticsearch",
      "version" : {
        "number" : "2.1.0",
        "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
        "build_timestamp" : "2015-11-18T22:40:03Z",
        "build_snapshot" : false,
        "lucene_version" : "5.3.1"
      },
      "tagline" : "You Know, for Search"
    }
    

    配置elasticsearch.yml 在config目录下

     ---------------------------------- Cluster -----------------------------------
    cluster.name: 你的引用
    node.name: node-101
    ----------------------------------- Paths ------------------------------------
    path.data: 数据路径
    path.logs: 日志路径
    ---------------------------------- Network -----------------------------------
    这里不贴出来了。配置成以下之后不知道为什么运行不起来
    network.host: 0.0.0.0
    http.port: 9200
    --------------------------------- Discovery ----------------------------------
    http.cors.enabled: true 
    http.cors.allow-origin: "*" 
    node.master: true 
    node.data: true 
    

    Sense安装

    Kibana安装

    • 具体地址官网下载即可
    • kibanan.yml修改
    server.port: 5601
    server.host: "localhost"
    elasticsearch.hosts: ["http://localhost:9200"]
    

    logstash安装

    在config中新建logstash.conf

    input {
    
        file {
    
            type => "nginx_access"
    
            path => "路径"
    
        }
    
    }
    
    output {
    
        elasticsearch {
            hosts => ["127.0.0.1:9200"]
            index => "access-%{+YYYY.MM.dd}"
        }
    
        stdout {
    
            codec => json_lines
        }
    }
    
    • 然后依次启动就行了。这里简单赘述下

    Serilog

    简介

    • Serilog 是一个用于.NET应用程序的日志记录开源库,配置简单,接口干净,并可运行在最新的.NET平台上,与其他日志库不同, Serilog 是以功能强大的结构化事件数据为基础构建的, 支持将日志输出到控制台、文件、数据库和其它更多的方式,支持参数化日志模板,非常灵活。
    • 首先,使用 NuGet 方式安装 Serilog 核心库
    Install-Package Serilog
    Install-Package Serilog.Sinks.Console
    
    //配置
     public static void ConfigureSerilogConfig(this IServiceCollection services, IConfiguration configuration)
            {
                Serilog.Log.Logger = new LoggerConfiguration()
                  .ReadFrom.Configuration(configuration)
                  .CreateLogger();
          }
    
    //json配置
      "Serilog": {
        "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Async", "Serilog.Sinks.File" ],
        "LevelSwitches": { "$controlSwitch": "Verbose" },
        "MinimumLevel": {
          "Default": "Information",
          "Override": {
            "Microsoft": "Debug",
            "System": "Debug",
            "System.Net.Http.HttpClient": "Debug"
          }
        },
        "WriteTo:Async": {
          "Name": "Async",
          "Args": {
            "configure": [
              { "Name": "Console" }
            ]
          }
        },
        "WriteTo:Elasticsearch": {
          "Name": "Elasticsearch",
          "Args": {
            "nodeUris": "http://localhost:9200;http://remotehost:9200/",
            "indexFormat": "operation-broadcast-api-{0:yyyy.MM.dd}",
            "autoRegisterTemplate": true
          }
        },
        "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
        "Properties": {
          "Application": "operation"
        }
      },
    

    具体得相关配置可以参照

    • serilog-settings-appsettings
    • serilog-settings-configuration
    • serilog-sinks-elasticsearch
      以上百度获取github里面都有说明。访问官方文档也可以
  • 相关阅读:
    第12讲:数据库完整性
    第11讲:视图及其应用
    第10讲:利用SQL语言实现关系代数操作
    ArcEngine 坐标系转换
    [转]ArcGIS计算图斑的四邻坐标(XMin,XMax,YMin,YMax)
    oracle11g 修改字符集 修改为ZHS16GBK
    Oracle 全文索引相关命令
    SQL语句 递归
    流量操控之SSH隧道与端口转发
    VIM 常用操作
  • 原文地址:https://www.cnblogs.com/ccaa/p/13138185.html
Copyright © 2011-2022 走看看