如何使用身份验证通过NLog或SeriLog登录到Elastic Search [英] How to Log to Elastic Search by NLog or SeriLog with authentications

查看:533
本文介绍了如何使用身份验证通过NLog或SeriLog登录到Elastic Search的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前使用的是Azure规模集(一个源组上的许多VM具有负载平衡和一个可用性集),我们过去使用NLog记录我们的Web应用操作和错误,但是现在我们要求/需要使用Elastic Search并且还将集中式日志用于所有Azure虚拟机实例,而不是每个实例使用文件.

We are currently use azure scale set (many VMs on one source group with load balance and one availability set), we used to use NLog to log our web app action and errors, but now we asked/needs to use Elastic Search and also use centralized log for all azure vm instances instead of file per each instance.

我是ES和LogStash概念的新手,是否需要用其他东西代替NLog?以及我该如何使用ES并统一所有日志(我想将nlog存储在azure存储表中作为统一结果,还是我需要使用LogStash还是您更喜欢其他东西)?

I am new to ES and LogStash concepts, Do I need to replace NLog with something else? and How I move to use ES and unify all logs in one (I think to make nlog store in azure storage table as unify results or do I needs to use LogStash or you prefer something else)?

如上所述,在zure多VM上提供对.net核心应用程序支持的最多日志记录是什么?

What is the most logging that give support for .net core app on azure multi VMs as described above?

请帮忙吗?

推荐答案

由于要登录ElasticSearch,最好使用支持结构化日志记录的日志记录框架,对于[NLog],此功能位于 beta RTM .

Since you want to log into ElasticSearch, it's best if you use a Logging framework that supports Structured Logging which for [NLog] this feature is in beta RTM.

您可以 Serilog 作为支持结构化日志记录的日志记录框架.

You can Serilog as your Logging Framework which supports Structured Logging.

还有用于ElasticSearch的Serilog接收器 https://github.com/serilog/serilog-下沉弹性搜索

And there's also Serilog sink for ElasticSearch https://github.com/serilog/serilog-sinks-elasticsearch

您应该将这些nuget包添加到您的项目中:

You should add these nuget packages to your project :

Serilog
Serilog.Sinks.ElasticSearch  

这是将Serilog的配置下沉到ElasticSearch

var logger = new LoggerConfiguration()
    .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
    {
        ModifyConnectionSettings = x => x.SetBasicAuthentication(username, password);
    })
    .CreateLogger();

这篇关于如何使用身份验证通过NLog或SeriLog登录到Elastic Search的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆