You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since .NET 6, the preferred way to log (according to Microsoft), is using the the LoggerMessageAttribute, which causes the source generation of a strongly typed log message. Quite often, the LogPropertiesAttribute is used with it, which will cause all properties of the object to be added as properties to the log.
A typical way to use this would look like this:
internalstaticpartialclassLogPropertiesExampleExtensions{[LoggerMessage(LogLevel.Information,Message="Example log of MyProps {MyProps}")]publicstaticpartialvoidLogMyProp(thisILoggerlogger,[LogProperties]MyPropsmyProps);}
where MyProps is a complex object that looks like this (stolen from a Microsoft.Extensions unit test):
The problem now is, that there doesn't seem to be a way to expand all properties of the object (MyProps) in Seq (so that it appears as proper highlighted json).
Seq has all the expanded properties at the top level but the JSON of its values are just dumb strings (no highlighting no expand and collapse) and I don't see a way to make them expand:
If I remove the [LogProperties] attributes so that the top level properties are not added to the log entry, I also do not get any expansion at all:
Trying to add an @ to the property in the template like this
internalstaticpartialclassLogPropertiesExampleExtensions{[LoggerMessage(LogLevel.Information,Message="Example log of MyProps {@MyProps}")]publicstaticpartialvoidLogMyProp(thisILoggerlogger,MyPropsmyProps);}
So as far as I can tell there doesn't seem to be any way to get the fully expanded object into Seq.
It would be very nice, if Seq could fully support the new way of logging with Microsoft.Extensions, if possible.
Note that I am currently not using Serilog as a logging provider for Microsoft.Extensions.Logging. Maybe there is a way to solve this problem if I would?
The text was updated successfully, but these errors were encountered:
HI @bitbonk; as far as we can tell, this is [LogProperties] functioning as intended; the message template's MyProps token is being filled with the ToString representation of the object, and the additional properties with dotted names are tacked on.
It doesn't seem like [LogProperties] is intended to function in the same manner as Serilog's @.
@nblumhardtVia an other issue (that involves log redaction using Microsoft.Extensions.Compliance.Redaction and Microsoft.Extensions.Telemetry) I have learned that there is a new way to expand everything: the Transitive property. For some reason it is marked as experimental though.
I also have not tested yet if the Transitive property plays nice with Seq. I suppose it should be logged in Seq as fully expanded objects (just as if I would have used "{@MyProps}").
Since .NET 6, the preferred way to log (according to Microsoft), is using the the LoggerMessageAttribute, which causes the source generation of a strongly typed log message. Quite often, the LogPropertiesAttribute is used with it, which will cause all properties of the object to be added as properties to the log.
A typical way to use this would look like this:
where MyProps is a complex object that looks like this (stolen from a Microsoft.Extensions unit test):
The problem now is, that there doesn't seem to be a way to expand all properties of the object (MyProps) in Seq (so that it appears as proper highlighted json).
When I log something like this
Seq has all the expanded properties at the top level but the JSON of its values are just dumb strings (no highlighting no expand and collapse) and I don't see a way to make them expand:
If I remove the
[LogProperties]
attributes so that the top level properties are not added to the log entry, I also do not get any expansion at all:Trying to add an @ to the property in the template like this
will give me the following compiler error:
So as far as I can tell there doesn't seem to be any way to get the fully expanded object into Seq.
It would be very nice, if Seq could fully support the new way of logging with Microsoft.Extensions, if possible.
Note that I am currently not using Serilog as a logging provider for Microsoft.Extensions.Logging. Maybe there is a way to solve this problem if I would?
The text was updated successfully, but these errors were encountered: