多个Serilog记录器 [英] Multiple Serilog Loggers

查看:120
本文介绍了多个Serilog记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有多个serilog记录器?当前,在我的WebApi中,我可以调用Log.Information例如记录信息事件,但是有没有办法我可以制作其他日志并从控制器中调用ExternalLog.Information或AuthenticationLog.Information?其背后的目的是我的Web api当前正在为不同但相互关联的项目使用多个不同的数据库,并且我想将日志存储在与它们相关的每个数据库中,而不需要创建一个额外的日志数据库(如果有的话)可能的.

Is it possible to have multiple serilog loggers? Currently within my WebApi I can call Log.Information for example to log an information event, but is there a way that I can instead make different logs and call ExternalLog.Information or AuthenticationLog.Information from my controller? The purpose behind this is that my web api is currently working with multiple different databases for different yet interrelated projects, and I would like to store logs within each of these databases that pertain to them instead of needing to create an additional logging database if at all possible.

我认为不太可能的一种更好的解决方案是,我可以将单个控制器映射到日志,以便在特定控制器每次调用日志时,都会将其写入AuthenticationLog.

A better solution, that I figure is less likely is, can I map individual controllers to a log, so that any time that a specific controller calls log, it writes to the AuthenticationLog for example.

推荐答案

我认为,此问题的答案是使用子记录器,而不是单独的记录器.我发现您可以执行 .WriteTo.Logger 并在其中进一步过滤.如果没有其他人有更好的解决方案(当然,如果我能够使它工作),我将接受此作为答案.我需要能够对控制器或动作名称进行过滤,这时我还有第二个堆栈溢出问题,以弄清楚如何获取该数据.使用Asp.net Web API的Serilog不使用浓缩器

I believe that the answer to this question is to use subloggers, rather than separate loggers. I have found that you can do .WriteTo.Logger and filter further in there. I will accept this as the answer if nobody else has a better solution (and of course if I am able to get it to work). I need to be able to filter on the controller or action name, which at this time I have a second stack overflow question out to figure out how to get that data. Serilog with Asp.net Web Api not using enricher

这篇关于多个Serilog记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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