目前我有用代码编写的所有配置。我使用子记录器进行筛选并更改记录的存储。有没有办法从配置文件中做到这一点。因为我想为解决方案中的每个上下文都有单独的配置文件。有没有办法通过配置文件配置Serilog子记录器?
1
A
回答
0
如果子记录器的数量是固定在编译的时候,你可以使用配置前缀来做到这一点:
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings() // default file
.WriteTo.Logger(lc => lc
.ReadFrom.AppSettings(filePath: "other1.config"))
.WriteTo.Logger(lc => lc
.ReadFrom.AppSettings(filePath: "other2.config"))
.CreateLogger();
有在Serilog.Settings.AppSettings不支持,但在理论上没有什么预防如果某人能够实施它,它会被添加。
0
试试这个
Startup.cs/Global.asax.cs中
Log.Logger = new LoggerConfiguration()
.WriteTo
.Logger(x => x.Filter
.ByIncludingOnly(logEvent => logEvent.Level == Serilog.Events.LogEventLevel.Error)
.ReadFrom
.AppSettings("error"))
.WriteTo
.Logger(x => x.Filter
.ByIncludingOnly(logEvent => logEvent.Level == Serilog.Events.LogEventLevel.Information)
.ReadFrom
.AppSettings("info")).CreateLogger()
的Web.Config
<add key ="error:serilog:using:RollingFile" value="Serilog.Sinks.RollingFile"/>
<add key ="error:serilog:write-to:RollingFile.pathFormat" value="C:\log\error {Date}.txt"/>
<add key ="error:serilog:write-to:RollingFile.formatter" value="Serilog.Formatting.Json.JsonFormatter"/>
<add key ="info:serilog:using:RollingFile" value="Serilog.Sinks.RollingFile"/>
<add key ="info:serilog:write-to:RollingFile.pathFormat" value="C:\log\info {Date}.txt"/>
<add key ="info:serilog:write-to:RollingFile.formatter" value="Serilog.Formatting.Json.JsonFormatter"/>
+0
请不要添加[相同的答案](http://stackoverflow.com/a/41989190/4687348)亩一些问题。回答最好的一个,并将其余标记为重复。请参阅[是否可以为几个问题添加重复答案?](http://meta.stackexchange.com/q/104227/347985) – FelixSFD
相关问题
- 1. 有没有办法通过appSetting配置配置多个Serilog RollingFiles
- 2. 通过配置文件设置python记录器配置
- 3. 从配置文件配置AzureTableStorage Serilog sink
- 4. 骡子配置模式没有记录
- 5. 有没有办法将Xcode自动配置文件选择器配置为某个团队配置文件?
- 6. 有条件通过记录Serilog
- 7. 有没有办法让配置“递归”?
- 8. 有没有办法在Protractor的配置中定义本地配置文件?
- 9. 通过配置记录NPoco
- 10. 通过XML配置使用Serilog Slack Sink
- 11. 配置Serilog通过app.config写入Slack
- 12. magento:有没有办法使用cron“运行配置文件”?
- 13. Mixpanel:有没有办法链接到用户配置文件?
- 14. 有没有办法从maven配置执行批处理文件?
- 15. 有没有办法在Perl中加载配置文件?
- 16. 有没有办法加载配置文件?
- 17. 有没有办法用不同的配置文件运行NUTCH?
- 18. 有没有办法使用Visual Studio配置管理器将配置文件从env文件夹中取出?
- 19. 有没有办法将日志记录器工厂添加到日志记录器配置中?
- 20. 有没有办法检查Apache配置文件中是否存在目录?
- 21. 有没有办法以编程方式配置铲子?
- 22. Log4j的-2.6.2基本配置没有配置记录等级
- 23. 有没有办法在EventLog接收器上设置事件ID(在Serilog中)?
- 24. 有没有办法通过配置文件来配置Python日志格式化程序来将时间记录为Unix时间戳?
- 25. 没有找到匹配配置文件
- 26. 有没有办法在Nginx配置里设置一个变量?
- 27. 有没有办法在DataSource配置中设置时区为UTC
- 28. 有没有办法在WebStorm中设置项目级配置?
- 29. 有没有办法为ruby-debug设置永久配置?
- 30. Java Servlet - 记录器和配置文件
这可能是有用的,[提问]:HTTP: //stackoverflow.com/a/41989190/7038900 – Spharah