Akka .Net Serilog配置语义日志记录不起作用。

huangapple go评论51阅读模式
英文:

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.

{
	&quot;name&quot;: &quot;AppTraces&quot;,
	&quot;time&quot;: &quot;2023-05-11T09:01:21.9089715Z&quot;,
	&quot;data&quot;: {
		&quot;baseType&quot;: &quot;MessageData&quot;,
		&quot;baseData&quot;: {
			&quot;ver&quot;: 2,
			&quot;message&quot;: &quot;Doing a thing on a log \&quot;MyExtraPropValue\&quot;&quot;,
			&quot;severityLevel&quot;: &quot;Information&quot;,
			&quot;properties&quot;: {
				&quot;LogSource&quot;: &quot;[akka://my-actor-system/user/my-actor#1234344381]&quot;,
				&quot;Timestamp&quot;: &quot;2023-05-11T09:01:21.9089046Z&quot;,
				&quot;Message&quot;: &quot;Doing a thing on a log \&quot;MyExtraPropValue\&quot;&quot;,
				&quot;Thread&quot;: &quot;0044&quot;,
				&quot;SourceContext&quot;: &quot;MyProject.MyActorClass&quot;,
				&quot;MessageTemplate&quot;: &quot;{Message:l}&quot;,
				&quot;ActorPath&quot;: &quot;akka://my-actor-system/user/my-actor&quot;
			}
		}
	}
}


The call to initialize the logger as a field in the actor looks like this:

private readonly ILoggingAdapter _logger = Context.GetLogger&lt;SerilogLoggingAdapter&gt;();

The call somewhere in my actor's receive looks like this.

_logger.Info(&quot;Doing a thing on a log &#39;{MyExtraPropName}&#39;&quot;, &quot;MyExtraPropValue&quot;);

This is the content of our HOCON file

akka 
{ 
    loglevel=INFO
    log-dead-letters = off
    log-dead-letters-during-shutdown = off 
    loggers=[&quot;Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog&quot;]
    logger-formatter=&quot;Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog&quot;
    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&lt;SerilogLoggingAdapter&gt;() 来检索 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 &quot;Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog&quot;
  • Do not use Context.GetLogger&lt;SerilogLoggingAdapter&gt;() to retrieve an ILoggingAdapter reference, use Context.GetLogger() instead.

huangapple
  • 本文由 发表于 2023年5月11日 19:37:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定