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.

[Question] How to compile MessageTemplate + Properties obtained from the HTTP sink?

See original GitHub issue

I’m trying to develop a logging server for my company using your HTTP sink, plugged into ASP.NET Core MVC.

The sink sends the following POST:

{
  "events": [
    {
      "Timestamp": "2017-03-07T02:07:34.8287216+07:00",
      "Level": "Information",
      "MessageTemplate": "Executing ViewResult, running view at path {Path}.",
      "Properties": {
        "Path": "/Views/Home/Index.cshtml",
        "EventId": { "Id": 1 },
        "SourceContext": "Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor",
        "ActionId": "606648ce-b9fc-4811-8e5d-9d15b5e037c8",
        "ActionName": "Sample.Controllers.HomeController.Index (Sample)",
        "RequestId": "0HL34OG547AUO",
        "RequestPath": "/"
      }
    },
    {
      "Timestamp": "2017-03-07T02:07:34.8718259+07:00",
      "Level": "Information",
      "MessageTemplate": "User profile is available. Using '{FullName}' as key repository and Windows DPAPI to encrypt keys at rest.",
      "Properties": {
        "FullName": "C:\\Users\\Ryan\\AppData\\Local\\ASP.NET\\DataProtection-Keys",
        "SourceContext": "Microsoft.Extensions.DependencyInjection.DataProtectionServices",
        "ActionId": "606648ce-b9fc-4811-8e5d-9d15b5e037c8",
        "ActionName": "Sample.Controllers.HomeController.Index (Sample)",
        "RequestId": "0HL34OG547AUO",
        "RequestPath": "/"
      }
    },
    {
      "Timestamp": "2017-03-07T02:07:35.0372262+07:00",
      "Level": "Information",
      "MessageTemplate": "Executed action {ActionName} in {ElapsedMilliseconds}ms",
      "Properties": {
        "ActionName": "Sample.Controllers.HomeController.Index (Sample)",
        "ElapsedMilliseconds": 3271.4887000000003,
        "EventId": { "Id": 2 },
        "SourceContext": "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker",
        "ActionId": "606648ce-b9fc-4811-8e5d-9d15b5e037c8",
        "RequestId": "0HL34OG547AUO",
        "RequestPath": "/"
      }
    },
    {
      "Timestamp": "2017-03-07T02:07:35.0467514+07:00",
      "Level": "Information",
      "MessageTemplate": "{HostingRequestFinished:l}",
      "Properties": {
        "ElapsedMilliseconds": 3598.5328,
        "StatusCode": 200,
        "ContentType": "text/html; charset=utf-8",
        "HostingRequestFinished": "Request finished in 3598.5328ms 200 text/html; charset=utf-8",
        "EventId": { "Id": 2 },
        "SourceContext": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
        "RequestId": "0HL34OG547AUO",
        "RequestPath": "/"
      },
      "Renderings": {
        "HostingRequestFinished": [
          {
            "Format": "l",
            "Rendering": "Request finished in 3598.5328ms 200 text/html; charset=utf-8"
          }
        ]
      }
    }
  ]
}

Which is cool. However, I’m stuck with the process of converting the MessageTemplate + Properties into a compiled message.

Is there an instruction for doing so? Thank you in advance.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
FantasticFiascocommented, Mar 7, 2017

Yes they do, its logEvent.MessageTemplate.Render(logEvent.Properties), you can see an example of it here.

0reactions
ryaneliancommented, Mar 12, 2017

Spicy. 🌶

Thank you for implementing and documenting this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add my own properties to Serilog output template
If you want to add properties that aren't part of the message template, then you need to enrich the log context.
Read more >
Serilog.Sinks.Http 8.0.0
In the following example, the sink will POST log events to http://www.mylogs.com over HTTP. We configure the sink using named arguments instead ...
Read more >
Serilog Best Practices - Ben Foster
Use the Serilog request logging middleware to log HTTP requests. This automatically includes many of the HTTP attributes listed above and ...
Read more >
HTTP Sink Connector for Confluent Cloud Quick Start
See Configuration Properties for configuration property descriptions. The HTTP Sink connector supports connecting to APIs using SSL along with Basic ...
Read more >
Serilog Tutorial - Structured Blog - Datalust
Console() adds the console sink to the pipeline; CreateLogger() assembles everything and returns a Logger object, which implements ILogger; The ...
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