diff --git a/Log4Net.Appender.Grafana.Loki.nuspec b/Log4Net.Appender.Grafana.Loki.nuspec index f611520..bc52fcf 100644 --- a/Log4Net.Appender.Grafana.Loki.nuspec +++ b/Log4Net.Appender.Grafana.Loki.nuspec @@ -2,7 +2,7 @@ $id$ - 1.0.5 + 1.1.0 $title$ loki.png Gabriel Cerutti diff --git a/Loki/Labels.cs b/Loki/Labels.cs index ef9cb7f..f1a0cf6 100644 --- a/Loki/Labels.cs +++ b/Loki/Labels.cs @@ -2,27 +2,15 @@ { public class LokiLabel { - public LokiLabel(string key, string value) - { - Key = key; - Value = value; - } + public string Key { get; set; } - public string Key { get; } - - public string Value { get; } + public string Value { get; set; } } public class LokiProperty { - public LokiProperty(string key, string value) - { - Key = key; - Value = value; - } - - public string Key { get; } + public string Key { get; set; } - public string Value { get; } + public string Value { get; set; } } } \ No newline at end of file diff --git a/LokiAppender.cs b/LokiAppender.cs index 04914bf..389aa82 100644 --- a/LokiAppender.cs +++ b/LokiAppender.cs @@ -1,5 +1,6 @@ using log4net.Appender; using log4net.Core; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; @@ -17,16 +18,19 @@ public class LokiAppender : BufferingAppenderSkeleton public string BasicAuthPassword { get; set; } public bool GZipCompression { get; set; } public bool TrustSelfSignedCerts { get; set; } + public LokiLabel Label { set { Labels.Add(value); } } + private List Labels = new List(); private void PostLoggingEvent(LoggingEvent[] loggingEvents) { - var labels = new LokiLabel[] { - new LokiLabel("Application", Application), - new LokiLabel("Environment", Environment) + var labels = new List(Labels) + { + new LokiLabel { Key = "Application", Value = Application }, + new LokiLabel { Key = "Environment", Value = Environment } }; var properties = new LokiProperty[] { - new LokiProperty("MachineName", System.Environment.MachineName), - new LokiProperty("ProcessName", Process.GetCurrentProcess().ProcessName) + new LokiProperty { Key = "MachineName", Value = System.Environment.MachineName }, + new LokiProperty { Key = "ProcessName", Value = Process.GetCurrentProcess().ProcessName } }; var formatter = new LokiBatchFormatter(labels, properties); var httpClient = new LokiHttpClient(TrustSelfSignedCerts); diff --git a/README.md b/README.md index b5f42ec..d0ed117 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ Sample Log4net config: + ```