Add property BetterStackLogsTarget.IncludeScopeContext#3
Open
menuet wants to merge 1 commit into
Open
Conversation
…se) in order to be able upload the ScopeContext's properties
Contributor
|
Notice that you inherit from TargetWithContext, which correctly handles ScopeContext. Where you can call See also: https://github.com/NLog/NLog/wiki/How-to-write-a-custom-target-for-structured-logging Maybe this will be better: protected override void Write(LogEventInfo logEvent)
{
var properties = GetAllProperties(logEvent); // Assign IncludeEventProperties = true in constructor
var contextDictionary = new Dictionary<string, object> {
["logger"] = logEvent.LoggerName,
["properties"] = properties,
["runtime"] = new Dictionary<string, object> {
["class"] = logEvent.CallerClassName,
["member"] = logEvent.CallerMemberName,
["file"] = string.IsNullOrEmpty(logEvent.CallerFilePath) ? null : logEvent.CallerFilePath,
["line"] = string.IsNullOrEmpty(logEvent.CallerFilePath) ? null : logEvent.CallerLineNumber as int?,
},
}; |
snakefoot
reviewed
Oct 7, 2024
| scopedProperties[prop.Key] = prop.Value; | ||
| } | ||
| if (scopedProperties != null) | ||
| contextDictionary["sc"] = scopedProperties; |
Contributor
There was a problem hiding this comment.
Acronyms like "sc" are not easy for others to understand
snakefoot
reviewed
Oct 7, 2024
| /// <summary> | ||
| /// Include Include ScopeContext's properties in logs. | ||
| /// </summary> | ||
| public bool IncludeScopeContext { get; set; } = false; |
Contributor
There was a problem hiding this comment.
NLog TargetWithContext already provides IncludeScopeProperties that works together with GetAllProperties()
Contributor
|
Created #7 that uses NLog JsonLayout for output of ScopeContext-properties. By specifying |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi
Currently, the target BetterStackLogsTarget uploads only the GlobalDiagnosticContext's properties.
It is useful for us to uplaod the ScopeContext's properties too.
So we duplicated and hacked your class in our code base for this purpose.
We made this PR in case you are interested to make this patch available to everyone (and for getting rid of our duplicate if yours does the job).
Regards