-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To improve debugging experience while integrating with Wilson
- Loading branch information
Showing
5 changed files
with
114 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Microsoft.IdentityModel.Logging | ||
{ | ||
/// <summary> | ||
/// A context class that can be used to store work per request to aid with debugging. | ||
/// </summary> | ||
public class LoggerContext | ||
{ | ||
/// <summary> | ||
/// Instantiates a new <see cref="LoggerContext"/> with the default activityId. | ||
/// </summary> | ||
public LoggerContext() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Instantiates a new <see cref="LoggerContext"/> with an activityId. | ||
/// </summary> | ||
/// <param name="activityId"></param> | ||
public LoggerContext(Guid activityId) | ||
{ | ||
ActivityId = activityId; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or set a <see cref="Guid"/> that will be used in the call to EventSource.SetCurrentThreadActivityId before logging. | ||
/// </summary> | ||
public Guid ActivityId { get; set; } = Guid.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets a boolean controlling if logs are written into the context. | ||
/// Useful when debugging. | ||
/// </summary> | ||
public bool CaptureLogs { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Gets or sets a string that helps with setting breakpoints when debugging. | ||
/// </summary> | ||
public string Id { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The collection of logs associated with a request. Use <see cref="CaptureLogs"/> to control capture. | ||
/// </summary> | ||
public ICollection<string> Logs { get; private set; } = new Collection<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets an <see cref="IDictionary{String, Object}"/> that enables custom extensibility scenarios. | ||
/// </summary> | ||
public IDictionary<string, object> PropertyBag { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/Microsoft.IdentityModel.Tokens.Tests/CallContextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.CodeDom; | ||
using Microsoft.IdentityModel.Logging; | ||
using Microsoft.IdentityModel.TestUtils; | ||
using Xunit; | ||
|
||
#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant | ||
|
||
namespace Microsoft.IdentityModel.Tokens.Tests | ||
{ | ||
public class CallContextTests | ||
{ | ||
[Theory, MemberData(nameof(CallContextTestTheoryData))] | ||
public void LoggerInstanceTests(CallContextTheoryData theoryData) | ||
{ | ||
var context = new CallContext(theoryData.ActivityId) { Id = theoryData.TestId }; | ||
|
||
Assert.IsAssignableFrom<LoggerContext>(context); | ||
Assert.Equal(theoryData.TestId, context.Id); | ||
Assert.Equal(theoryData.ActivityId, context.ActivityId); | ||
Assert.False(context.CaptureLogs); | ||
Assert.Empty(context.Logs); | ||
Assert.Null(context.PropertyBag); | ||
} | ||
|
||
public static TheoryData<TheoryDataBase> CallContextTestTheoryData | ||
{ | ||
get | ||
{ | ||
var theoryData = new TheoryData<TheoryDataBase>(); | ||
|
||
theoryData.Add(new CallContextTheoryData | ||
{ | ||
TestId = "abdc", | ||
ActivityId = new Guid() | ||
}); | ||
|
||
return theoryData; | ||
} | ||
} | ||
} | ||
|
||
public class CallContextTheoryData : TheoryDataBase | ||
{ | ||
public Guid ActivityId; | ||
} | ||
} | ||
|
||
#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant |