Skip to content

Commit

Permalink
Adds IdentityProvider into settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernarden committed Dec 5, 2018
1 parent a52b2ba commit 5f0e1d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn
return;
}

var allParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var allParameters = GetGlobalAndLocalLoggingParameters(parameters);
var traceTelemetry = new TraceTelemetry(message)
{
SeverityLevel = LoggingLevelMapper.ConvertLoggingLevelToSeverityLevel(loggingLevel)
Expand All @@ -77,7 +77,7 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev
return;
}

var allParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var allParameters = GetGlobalAndLocalLoggingParameters(parameters);
var exceptionTelemetry = new ExceptionTelemetry(exception)
{
SeverityLevel = LoggingLevelMapper.ConvertLoggingLevelToSeverityLevel(loggingLevel)
Expand Down
11 changes: 9 additions & 2 deletions Source/Vima.LoggingAbstractor.Core/AbstractLoggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ protected bool ShouldBeTraced(LoggingLevel loggingLevel)
/// </summary>
/// <param name="localParameters">The logging parameters that are explicitly specified by the user on logging call.</param>
/// <returns>All parameters to be logged.</returns>
protected IEnumerable<ILoggingParameter> GetGlobalAndLocalLoggingParameters(IEnumerable<ILoggingParameter> localParameters)
protected IList<ILoggingParameter> GetGlobalAndLocalLoggingParameters(IEnumerable<ILoggingParameter> localParameters)
{
var globalAndLocalParameters = localParameters.Concat(_settings.GlobalLoggingParameters);
var globalAndLocalParameters = localParameters.Concat(_settings.GlobalLoggingParameters).ToList();

var globalIdentityParameter = _settings.IdentityProvider?.Invoke();
if (globalIdentityParameter != null)
{
globalAndLocalParameters.Add(new LoggingIdentityParameter(globalIdentityParameter));
}

return globalAndLocalParameters;
}
}
Expand Down
11 changes: 10 additions & 1 deletion Source/Vima.LoggingAbstractor.Core/AbstractLoggerSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Vima.LoggingAbstractor.Core.Parameters;

namespace Vima.LoggingAbstractor.Core
Expand Down Expand Up @@ -29,5 +30,13 @@ public IEnumerable<ILoggingParameter> GlobalLoggingParameters
get => _globalLoggingParameters ?? (_globalLoggingParameters = new List<ILoggingParameter>());
set => _globalLoggingParameters = value;
}

/// <summary>
/// Gets or sets the identity provider.
/// </summary>
/// <value>
/// The identity provider.
/// </value>
public Func<IdentityParameter> IdentityProvider { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public LoggingIdentityParameter(string identity, string name = null)
Value = new IdentityParameter(identity, name);
}

/// <summary>
/// Initializes a new instance of the <see cref="LoggingIdentityParameter"/> class.
/// </summary>
/// <param name="identityParameter">The identity parameter.</param>
public LoggingIdentityParameter(IdentityParameter identityParameter)
{
Value = identityParameter ?? throw new ArgumentNullException(nameof(identityParameter));
}

/// <summary>
/// Gets the parameter's value.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Source/Vima.LoggingAbstractor.Raygun/RaygunAbstractLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn
return;
}

IEnumerable<ILoggingParameter> loggingParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var loggingParameters = GetGlobalAndLocalLoggingParameters(parameters);
SetIdentityParameters(loggingParameters);
var messageException = new RaygunMessageException(message);
var data = ExtractDataValues(loggingParameters);
Expand All @@ -74,7 +74,7 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev
return;
}

IEnumerable<ILoggingParameter> loggingParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var loggingParameters = GetGlobalAndLocalLoggingParameters(parameters);
SetIdentityParameters(loggingParameters);
var data = ExtractDataValues(loggingParameters);
var tags = ExtractTags(loggingParameters, loggingLevel);
Expand Down
4 changes: 2 additions & 2 deletions Source/Vima.LoggingAbstractor.Sentry/SentryAbstractLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn
return;
}

IEnumerable<ILoggingParameter> loggingParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var loggingParameters = GetGlobalAndLocalLoggingParameters(parameters);
Dictionary<string, string> tags = GenerateTags(loggingParameters);
_ravenClient.Capture(new SentryEvent(message)
{
Expand All @@ -76,7 +76,7 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev
return;
}

IEnumerable<ILoggingParameter> loggingParameters = GetGlobalAndLocalLoggingParameters(parameters).ToList();
var loggingParameters = GetGlobalAndLocalLoggingParameters(parameters);
Dictionary<string, string> tags = GenerateTags(loggingParameters);
_ravenClient.Capture(new SentryEvent(exception)
{
Expand Down

0 comments on commit 5f0e1d9

Please sign in to comment.