-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MessageTemplate Property #11
Comments
Dropping two classes in your project should do the trick for the time being: using System;
namespace MessagTemplateSerilog
{
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.Loki;
class Program
{
static void Main(string[] args)
{
var log = new LoggerConfiguration().
Enrich.WithMessageTemplate().
WriteTo.LokiHttp(new NoAuthCredentials("http://localhost:3100")).CreateLogger();
log.Information("An int {name} with a value {value}", "myIntName", 8);
log.Dispose();
}
}
public class MessageTemplateEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
LogEventProperty property = propertyFactory.CreateProperty("Message_Template", logEvent.MessageTemplate.Text);
logEvent.AddPropertyIfAbsent(property);
}
}
public static class MessageTemplateEnricherExtensions
{
public static LoggerConfiguration WithMessageTemplate(
this LoggerEnrichmentConfiguration enrichmentConfiguration)
{
if (enrichmentConfiguration == null)
throw new ArgumentNullException(nameof(enrichmentConfiguration));
return enrichmentConfiguration.With<MessageTemplateEnricher>();
}
}
} Keep in mind that you'll have to use a regex search (using
|
I’d like to know that how to use serilog.loki to establish a customizing client to make an index for writing logs as Elasticsearch.? |
Is there any way to get the message template sent along (may as a label?)? I would like to filter in loki based on all the entries with a specific Message Template
The text was updated successfully, but these errors were encountered: