Skip to content

Commit

Permalink
Merge branch 'release/0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
markjackmilian committed Oct 5, 2021
2 parents a722c48 + b29bc98 commit f885747
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Serilog.Core;
using Serilog.Events;
using Xamarin.Essentials;

namespace nightly.serilog.xamarin.Enrichers.DeviceInfo
{
public class DeviceIdEnricher : ILogEventEnricher
{
private LogEventProperty _cachedProperty;

public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (this._cachedProperty == null)
{
var idValue = SecureStorage.GetAsync("ENRICHER_ID").Result;
if (idValue == null)
{
idValue = Guid.NewGuid().ToString("N");
SecureStorage.SetAsync("ENRICHER_ID", idValue).Wait();
}

this._cachedProperty = propertyFactory.CreateProperty("DeviceId", idValue);
}
logEvent.AddPropertyIfAbsent(this._cachedProperty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
using nightly.serilog.xamarin.Enrichers.Version;
using Serilog;
using Serilog.Configuration;
using Xamarin.Essentials;

namespace nightly.serilog.xamarin
{
public static class EnrichersConfigurationExtensions
{

/// <summary>
/// Add univoque id to device
/// Value is stored in SecureStorage
/// </summary>
/// <param name="enrichment"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static LoggerConfiguration WithDeviceId(this LoggerEnrichmentConfiguration enrichment)
{
if (enrichment == null) throw new ArgumentNullException(nameof(enrichment));
return enrichment.With<DeviceIdEnricher>();
}

/// <summary>
/// Add Session Id
/// </summary>
Expand Down

0 comments on commit f885747

Please sign in to comment.