英文:
Akka .Net Serilog Configuration semantic logging won't work
问题
After upgrading to Akka .Net 1.5 we seem to have lost our semantic properties. I followed this guide to fix it: https://getakka.net/articles/utilities/serilog.html
However it seems to have no effect. The logs are coming through without the additional properties.
Our Serilog is assigned after it is configured in our application:
Log.Logger = config.CreateLogger();
And I can confirm this config is used since I can see application insights logs. However the logs always come through in the same incorrect way without additional properties.
{
"name": "AppTraces",
"time": "2023-05-11T09:01:21.9089715Z",
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Doing a thing on a log 'MyExtraPropValue'",
"severityLevel": "Information",
"properties": {
"LogSource": "[akka://my-actor-system/user/my-actor#1234344381]",
"Timestamp": "2023-05-11T09:01:21.9089046Z",
"Message": "Doing a thing on a log 'MyExtraPropValue'",
"Thread": "0044",
"SourceContext": "MyProject.MyActorClass",
"MessageTemplate": "{Message:l}",
"ActorPath": "akka://my-actor-system/user/my-actor"
}
}
}
}
The call to initialize the logger as a field in the actor looks like this:
private readonly ILoggingAdapter _logger = Context.GetLogger<SerilogLoggingAdapter>();
The call somewhere in my actor's receive looks like this.
_logger.Info("Doing a thing on a log '{MyExtraPropName}'", "MyExtraPropValue");
This is the content of our HOCON file
akka
{
loglevel=INFO
log-dead-letters = off
log-dead-letters-during-shutdown = off
loggers=["Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog"]
logger-formatter="Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog"
actor {
ask-timeout = 60s
}
}
英文:
After upgrading to Akka .Net 1.5 we seem to have lost our semantic properties. I followed this guide to fix it:
https://getakka.net/articles/utilities/serilog.html
However it seems to have no effect. The logs are coming through without the additional properties.
Our Serilog is assigned after it is configured in our application:
Log.Logger = config.CreateLogger();
And I can confirm this config is used since I can see application insights logs. However the logs always come through in the same incorrect way without additional properties.
{
"name": "AppTraces",
"time": "2023-05-11T09:01:21.9089715Z",
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Doing a thing on a log \"MyExtraPropValue\"",
"severityLevel": "Information",
"properties": {
"LogSource": "[akka://my-actor-system/user/my-actor#1234344381]",
"Timestamp": "2023-05-11T09:01:21.9089046Z",
"Message": "Doing a thing on a log \"MyExtraPropValue\"",
"Thread": "0044",
"SourceContext": "MyProject.MyActorClass",
"MessageTemplate": "{Message:l}",
"ActorPath": "akka://my-actor-system/user/my-actor"
}
}
}
}
The call to initialize the logger as a field in the actor looks like this:
private readonly ILoggingAdapter _logger = Context.GetLogger<SerilogLoggingAdapter>();
The call somewhere in my actor's receive looks like this.
_logger.Info("Doing a thing on a log '{MyExtraPropName}'", "MyExtraPropValue");
This is the content of our HOCON file
akka
{
loglevel=INFO
log-dead-letters = off
log-dead-letters-during-shutdown = off
loggers=["Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog"]
logger-formatter="Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog"
actor {
ask-timeout = 60s
}
}
答案1
得分: 1
Akka 1.5 中引入的一个重要更改是自定义日志消息格式化程序的添加,这显然与旧的 Serilog 日志流不兼容。我们将尝试在将来的版本中修复此问题。
在此期间,可以使用以下解决方法:
- 确保
Akka.Logger.Serilog
版本至少为 1.5.0.1(截至目前为止) - 确保将
akka.logger-formatter
设置为"Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog"
- 不要使用
Context.GetLogger<SerilogLoggingAdapter>()
来检索ILoggingAdapter
引用,而应改用Context.GetLogger()
。
英文:
One of the breaking changes introduced in Akka 1.5 is the addition of custom log message formatter, and this apparently is not compatible with the old serilog logging flow. We will try and fix this in future releases.
In the mean time, a workaround is:
- Make sure
Akka.Logger.Serilog
version is at least 1.5.0.1 (as of this writing) - Make sure that you set
akka.logger-formatter
to"Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog"
- Do not use
Context.GetLogger<SerilogLoggingAdapter>()
to retrieve anILoggingAdapter
reference, useContext.GetLogger()
instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论