diff --git a/nightly.serilog.xamarin/nightly.serilog.xamarin/Enrichers/SessionIdEnricher.cs b/nightly.serilog.xamarin/nightly.serilog.xamarin/Enrichers/SessionIdEnricher.cs
index 67b4b6e..10701fd 100644
--- a/nightly.serilog.xamarin/nightly.serilog.xamarin/Enrichers/SessionIdEnricher.cs
+++ b/nightly.serilog.xamarin/nightly.serilog.xamarin/Enrichers/SessionIdEnricher.cs
@@ -7,10 +7,16 @@ namespace nightly.serilog.xamarin.Enrichers
public class SessionIdEnricher : ILogEventEnricher
{
private LogEventProperty _cachedProperty;
+ private readonly string _sessionId;
+
+ public SessionIdEnricher(string sessionId = null)
+ {
+ this._sessionId = sessionId ?? Guid.NewGuid().ToString("N");
+ }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
- this._cachedProperty ??= propertyFactory.CreateProperty("SessionId",Guid.NewGuid().ToString("N"));
+ this._cachedProperty ??= propertyFactory.CreateProperty("SessionId",this._sessionId);
logEvent.AddPropertyIfAbsent(this._cachedProperty);
}
}
diff --git a/nightly.serilog.xamarin/nightly.serilog.xamarin/EnrichersConfigurationExtensions.cs b/nightly.serilog.xamarin/nightly.serilog.xamarin/EnrichersConfigurationExtensions.cs
index bbd09f7..4a51b46 100644
--- a/nightly.serilog.xamarin/nightly.serilog.xamarin/EnrichersConfigurationExtensions.cs
+++ b/nightly.serilog.xamarin/nightly.serilog.xamarin/EnrichersConfigurationExtensions.cs
@@ -42,10 +42,10 @@ public static LoggerConfiguration WithDeviceId(this LoggerEnrichmentConfiguratio
///
///
///
- public static LoggerConfiguration WithSessionId(this LoggerEnrichmentConfiguration enrichment)
+ public static LoggerConfiguration WithSessionId(this LoggerEnrichmentConfiguration enrichment, string sessionId = null)
{
if (enrichment == null) throw new ArgumentNullException(nameof(enrichment));
- return enrichment.With();
+ return enrichment.With(new SessionIdEnricher(sessionId));
}
///