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
I have two questions regarding the Compile-time logging source generation.
The first one is that I noticed that I get the analyzer warning SYSLIB1015 that an argument is not in the message but it is in the method signature.
For example:
[LoggerMessage( EventId =0, Level = LogLevel.Information, Message ="Look a log message for `{Name}`")]publicstaticpartialvoidTestMessage(ILoggerlogger,stringname,DateTimeOffsetwhenSaidName);
The whenSaidName is not not in the message so the SYSLIB1015 is clearly valid in that case.
However, I noticed that the generated code actually makes a state struct and adds the whenSaidName to its set, which as a bonus with Application insights is stored in the log custom properties because the generated state is of the type IReadOnlyList<KeyValuePair<string, object?>>, which I what I want.
Now I am actually wondering if it is safe to ignore that warning, even in the future, or if it is actually recommended to not do this and stick to the scopes as it can break in the future.
Because at the moment it removes the need to start a scope beforehand and then invoke the method, and the additional unused parameters are really just for enriching the log entries in application insights, and should not be part of the message.
The second question is an expansion of the first one.
Sometimes I have an ambient state that I want to pass to the logging, and I did that with the BeginScope and having an extension on the ambient state that creates a Dictionary<string, object>.
However I was wondering if in some way I can just pas Dictionary<string,object> to a compile time log method, and that the source generation copies all keys and values from that dictionary into its generated state object. This to just avoid adding everywhere a scope before every log and simplify the line a bit as like below.
It is minimal difference, but flattens it more. Is that somehow possible or just a wishful desire?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have two questions regarding the Compile-time logging source generation.
The first one is that I noticed that I get the analyzer warning SYSLIB1015 that an argument is not in the message but it is in the method signature.
For example:
The
whenSaidName
is not not in the message so theSYSLIB1015
is clearly valid in that case.However, I noticed that the generated code actually makes a state struct and adds the
whenSaidName
to its set, which as a bonus with Application insights is stored in the log custom properties because the generated state is of the typeIReadOnlyList<KeyValuePair<string, object?>>
, which I what I want.Now I am actually wondering if it is safe to ignore that warning, even in the future, or if it is actually recommended to not do this and stick to the scopes as it can break in the future.
Because at the moment it removes the need to start a scope beforehand and then invoke the method, and the additional unused parameters are really just for enriching the log entries in application insights, and should not be part of the message.
The second question is an expansion of the first one.
Sometimes I have an ambient state that I want to pass to the logging, and I did that with the
BeginScope
and having an extension on the ambient state that creates aDictionary<string, object>
.However I was wondering if in some way I can just pas
Dictionary<string,object>
to a compile time log method, and that the source generation copies all keys and values from that dictionary into its generated state object. This to just avoid adding everywhere a scope before every log and simplify the line a bit as like below.It is minimal difference, but flattens it more. Is that somehow possible or just a wishful desire?
Beta Was this translation helpful? Give feedback.
All reactions