Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Log4Net.Appender.Grafana.Loki.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>$id$</id>
<version>1.0.5</version>
<version>1.1.0</version>
<title>$title$</title>
<icon>loki.png</icon>
<authors>Gabriel Cerutti</authors>
Expand Down
20 changes: 4 additions & 16 deletions Loki/Labels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
14 changes: 9 additions & 5 deletions LokiAppender.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using log4net.Appender;
using log4net.Core;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand All @@ -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<LokiLabel> Labels = new List<LokiLabel>();

private void PostLoggingEvent(LoggingEvent[] loggingEvents)
{
var labels = new LokiLabel[] {
new LokiLabel("Application", Application),
new LokiLabel("Environment", Environment)
var labels = new List<LokiLabel>(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);
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Sample Log4net config:
<BasicAuthPassword value="password" /> <!-- To be added if basic authent enabled -->
<GZipCompression value="true" /> <!-- To compress the post request using GZip compression -->
<TrustSelfSignedCerts value="false" /> <!-- To trust self signed certificates. Default: false -->
<Label> <!-- Add custom label -->
<Key value="apiGroup" />
<Value value="group1" />
</Label>
</appender>
</log4net>
```