question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract Dictionary values from LogEventProperty

See original GitHub issue

There 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
abrasatcommented, May 24, 2019

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.

0reactions
bartelinkcommented, May 23, 2019

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found