Skip to content

Commit

Permalink
dev: pass sessionid as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
markjackmilian committed Dec 20, 2022
1 parent cd96a42 commit 8a13a80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static LoggerConfiguration WithDeviceId(this LoggerEnrichmentConfiguratio
/// <param name="enrichment"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
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<SessionIdEnricher>();
return enrichment.With(new SessionIdEnricher(sessionId));
}

/// <summary>
Expand Down

0 comments on commit 8a13a80

Please sign in to comment.