Extract Dictionary values from LogEventProperty
See original GitHub issueThere is a use-case where our application stores in the LogEvent properties a Dictionary<string,object> element:
var embeddedLogCtx = new Dictionary<string, object>();
DateTimeOffset embeddedLogTimeStamp = GetEmbeddedLogTimeStamp(..);
embeddedLogCtx["App"] = "MyEmbeddedApp";
embeddedLogCtx["Function"] = "MyEmbeddedAppFunct";
embeddedLogCtx["TS"] = embeddedLogTimeStamp;
var logLevel = GetLogLevelFromEmbeddedLogLevel(...);
logger.Log(logLevel, "{@Context}", embeddedLogCtx);
How can be extracted the “TS” DateTimeOffset from the properties of the LogEvent object in a serilog sink or enricher ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Serilog Custom Sink Formatting Issue with ...
I've tried converting the out value from the dictionary into a string and then removing the unwanted attributes but nothing is working for ......
Read more >How to Extract Dictionary Values as a List
Here are 3 approaches to extract dictionary values as a list in Python: (1) Using a list() function: my_list = list(my_dict.values()).
Read more >Ways to extract all dictionary values | Python
Method #1 : Using loop + keys() The first method that comes to mind to achieve this task is the use of loop...
Read more >[Solved]-How to format serilog property names?-C#
I will update if any bugs are found. public class LogEventPropertiesNameFormatter { public void Format(LogEvent logEvent) { var keys = new List<string>(logEvent ...
Read more >Serilog Best Practices - Ben Foster
Logs help to reason about your application and diagnose issues. You should review your production logs regularly to ensure they provide value.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the hint, it put me on the right direction! Actually I did not change the message template, but used a dictionary property with one of the items containing the timestamp. In the sink I extracted the timestamp and then removed it from the dictionary when re-creating the LogEvent.
In that case, it seems you just need to override the message template for your Sink to not include the timestamp ? (worth inclding a snipet of your LoggerConfiguration if trying to explain complications)