首页 > 其他分享 >Serilog.Sinks.Elasticsearch 写username到 ES失败

Serilog.Sinks.Elasticsearch 写username到 ES失败

时间:2023-04-07 21:44:16浏览次数:48  
标签:username use Sinks Serilog es log

Using the lib: Serilog.Sinks.Elasticsearch and ECS-dotnet which provide the ecs format, we can write log into es in ECS format.

I have been able to overall link trace,  now, I want to record the username if user has logged.

Astonoshingly, sometime, it works,then fail!

for a long time, I think this because the ecs format do some odd thing.

then I find the root cause:

My application  record log in es and file.

if I just log in file, the username can be recorded, if the log in es, the use name will lose.

username can be seen in middware, but when to send to es, the httpcontext.user become lost!

Loging in  file use Serilog.Sinks.File.  Meanwhile  Logging in ES use Serilog.Sinks.Elasticsearch which dot use the request thread. So the IHttpContextAccessor.Httpcontext will become null!

I konw he ThreadId was recorded in es, so it seems that the user name also can be recorded!

At least, we can add a middleware to recored the property

 

标签:username,use,Sinks,Serilog,es,log
From: https://www.cnblogs.com/qgbo/p/17297455.html

相关文章

  • 在AspNet Core项目中集成Serilog
    1.引入Nuget包Serilog.AspNetCore2.配置SerilogusingSerilog;Log.Logger=newLoggerConfiguration().WriteTo.Console()//添加console日志输出.WriteTo.Debug()//添加debug日志输出.CreateLogger();try{Log.Information("Startingwebapplicat......
  • Django外键引用User模型时显示username的解决方法
    问题需求:在DjangoAdmin后台模型管理中,引用User外键的字段,显示的是username(用户名)。下拉菜单要显示姓名(last_name和first_name,外加username保持唯一性、可辨别性)。使用代理模型(proxymodel)fromdjango.dbimportmodelsfromdjango.contrib.auth.modelsimportUser#创建代......
  • ABP VNext 的日志机制 + SeriLog
    **ABPVNext的日志机制**正用ABPVNext做个系统,由于框架默认带来日志处理机制,开发阶段基本能用,也一直没有去动它,快要上线了,思考了一下正式环境的日志管理流程,由于系统不大,预计访问量可能也不大,但默认的日志管理太简单,不便于后期日常维护。缺点如下:默认的日志只有单个文件,写上几......
  • ABP VNext 的日志机制 + SeriLog
    **ABPVNext的日志机制**正用ABPVNext做个系统,由于框架默认带来日志处理机制,开发阶段基本能用,也一直没有去动它,快要上线了,思考了一下正式环境的日志管理流程,由于系统不......
  • WebApi 单文件发布Serilog 失效
    提问WebApi单文件发布Serilog失效怎么解决回答配置文件Appsetting.json增加Using块"Using":["Serilog.Sinks.Console","Serilog.Sinks.File"],示例{"Seril......
  • python连接oracle 19c报错误ORA-01017: invalid username/password
    环境:db:19cpython:3.6最近有使用到cx_oracle(5.3)模块,这里记录下出现的问题由于我的项目一直在是windows上测试,最近把项目更新到linux下后,再去跑代码,发现代码报出ORA-2......
  • Serilog .Net Core简单配置使用
    publicclassProgram{publicstaticvoidMain(string[]args){Log.Logger=newLoggerConfiguration().Minim......
  • 关于net core 开发服务时,使用Serilog根据appsettings.json输出日志错误的问题。
    使用Serilog输出日志时,配置内容如下,"Serilog":{"Using":["Serilog.Sinks.Console","Serilog.Sinks.File"],"MinimumLevel":"Debug","WriteTo":[......
  • 2- 用户登录表单拦截 UsernamePasswordAuthenticationFilter
    /**Copyright2004,2005,2006AcegiTechnologyPtyLimited**LicensedundertheApacheLicense,Version2.0(the"License");*youmaynotusethisf......
  • [ABC268D] Unique Username 题解
    [ABC268D]UniqueUsernameSolution目录[ABC268D]UniqueUsernameSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面给定$n$各字......