Как автоматически генерировать Индекс за день, используя Serilog в упругом поиске - PullRequest
1 голос
/ 10 октября 2019

Iam с использованием serilog 2.8 с каркасом dotnet 4.8. Та же самая система регистрации подключается кasticsearch с помощью приведенного ниже кода.

    var isxyz = Matching.FromSource("xyz");
    var elasticUrl = ConfigurationManager.GetSetting("elasticurl", "http://localhost:9200"); 
    var environment= ConfigurationManager.GetSetting("environment", "test").ToLowerInvariant();
    string servicename = "john.processExecutor";
    var indexname = $"{servicename.ToLowerInvariant()}.{environment}.{DateTime.Now.ToString("yyyyMMdd")}";
    Log.Logger = new LoggerConfiguration()

    .Enrich.WithProperty("ServiceName", servicename)
    .Enrich.FromLogContext()
    .MinimumLevel.Debug()

    .WriteTo.Logger(l => l.WriteTo.Console())

       .WriteTo.Logger(l => l.Filter.ByIncludingOnly(m => isxyz(m))
        .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUrl))
        {
            AutoRegisterTemplate = true,
            AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
             IndexFormat = indexname
        })
        .WriteTo.File(AppDomain.CurrentDomain.BaseDirectory + "Logs" + "\\" + "Application-.txt", rollingInterval: RollingInterval.Day,
        outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
     )

    .WriteTo.Logger(l => l.Filter.ByIncludingOnly(m => isxyz(m)).WriteTo
    .File(AppDomain.CurrentDomain.BaseDirectory + "Logs" + "\\" + "log-.txt", rollingInterval: RollingInterval.Day,
    outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] [{FilePath}]  [{MemberName}] [{LineNumber}] [{ServiceName}] [{CountryCode}] [{Message:lj}{NewLine}{Exception}]"))

    .WriteTo.Logger(l => l.WriteTo
    .File(AppDomain.CurrentDomain.BaseDirectory + "Logs" + "\\" + "fulllog-.txt", rollingInterval: RollingInterval.Day,
     outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] [{FilePath}] [{MemberName}] [{LineNumber}] [{ServiceName}] [{CountryCode}] [{Message:lj}{NewLine}{Exception}]"))

    .CreateLogger();

Я хочу автоматически генерировать индекс в день. Я пытался использовать indexdecider. Но не понимаю, как этого добиться.

...