Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
build:
name: Build, Test, and Release
runs-on: ubuntu-latest

steps:
- name: Set Time Zone to Europe/London
shell: pwsh
Expand All @@ -60,12 +60,12 @@ jobs:
echo "Is Stable: $STRAVAIG_IS_STABLE"

- uses: actions/setup-dotnet@v4
name: Setup .NET 6.0, 7.0 & 8.0
name: Setup .NET 6.0, 8.0 & 9.0
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x

- name: .NET State
run: dotnet --info
Expand Down Expand Up @@ -181,4 +181,4 @@ jobs:
message: "[bot] Post v${{ env.STRAVAIG_PACKAGE_FULL_VERSION }} release updates & bump version."
push: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A logger for use in tests so that the messages logged can be examined in tests.
.NET support:
* v1.x supports .NET Core 3.1 and .NET 5.0
* v2.x supports .NET 6.0, 7.0 and 8.0
* v3.x supports .NET 6.0 and 8.0
* v3.x supports .NET 6.0, 8.0 & 9.0

## Why test logs?

Expand Down Expand Up @@ -45,4 +45,4 @@ You can create a [GitHub issue](https://github.com/Stravaig-Projects/Stravaig.Ex
* At a PowerShell prompt
* Navigate to the root of this repository
* Run `./Install-GitHooks.ps1`
* Name the branch after the issue number. e.g. `#1234/fix-the-thing`. The Git Hooks will prefix each commit with the issue number.
* Name the branch after the issue number. e.g. `#1234/fix-the-thing`. The Git Hooks will prefix each commit with the issue number.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ v1.x supports: .NET Core 3.1 and .NET 5.0

v2.x supports: .NET 6.0, 7.0 and 8.0

v3.x supports: .NET 6.0 and 8.0
v3.x supports: .NET 6.0, 8.0 & 9.0

## Other Stuff

Expand Down
7 changes: 5 additions & 2 deletions release-notes/wip-release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Date: ???
### Breaking Changes

- Feature #123 changes the `TestCaptureLogger<T>` class to encapsulate an instance of `TestCaptureLogger` rather than inherit from it. If you're code relied on `TestCaptureLogger<T>` inheriting from `TestCaptureLogger` then it will likely break.
- Feature #172 drops support for .NET 7.0. Use .NET 6.0 LTS or .NET 8.0 LTS.
- Feature #172 drops support for .NET 7.0. Use .NET 6.0 LTS, .NET 8.0 LTS or .NET 9.0 STS.

### Bugs

Expand All @@ -27,10 +27,13 @@ Date: ???
- #164: Update pipeline.
- #172: Drop support and package targeting for .NET 7.0.
- #179: Update github pages pipeline
- #181: Add support for .NET 9.0

### Dependencies

- #166 & #172 Update package references:
- #166, #172 & #181 Update package references:
- .NET 9.0 targets:
- Added
- .NET 8.0 targets:
- Bump Microsoft.Extensions.Logging.Abstractions to 8.0.2
- .NET 7.0 targets:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>12</LangVersion>
</PropertyGroup>
Expand All @@ -14,17 +14,17 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<YEAR>$([System.DateTime]::Now.Year)</YEAR>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<Title>XUnit extensions for Stravaig Logging Capture for Tests</Title>
<Authors>Colin Angus Mackay</Authors>
<Copyright>©$2023-(YEAR) Colin Angus Mackay. See licence for more information.</Copyright>
Expand All @@ -16,7 +16,7 @@
XUnit extensions for Stravaig Logging Capture for Tests.

Use version 2.x for .NET 6.0 onwards.
Use version 3.x for .NET 6.0 &amp; 8.0 onwards.
Use version 3.x for .NET 6.0, 8.0 &amp; 9.0 onwards.
</Description>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
Expand Down
5 changes: 4 additions & 1 deletion src/Stravaig.Extensions.Logging.Diagnostics.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LogMessageIsSentenceProblem/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/RunLongAnalysisInSwa/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">ShowAndRun</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nupkg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shouldly/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stravaig/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=snupkg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stravaig/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=timedatectl/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
36 changes: 22 additions & 14 deletions src/Stravaig.Extensions.Logging.Diagnostics/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
using System.Text;
using Microsoft.Extensions.Logging;

#if NET9_0_OR_GREATER
using System.Threading;
#endif

namespace Stravaig.Extensions.Logging.Diagnostics;

/// <summary>
Expand All @@ -14,45 +18,49 @@ namespace Stravaig.Extensions.Logging.Diagnostics;
public class LogEntry : IComparable<LogEntry>
{
private static int _sequence;
private static readonly object SequenceSyncLock = new ();
#if NET9_0_OR_GREATER
private static readonly Lock SequenceSyncLock = new();
#else
private static readonly object SequenceSyncLock = new();
#endif

private const string OriginalMessagePropertyName = "{OriginalFormat}";

private readonly Lazy<IReadOnlyDictionary<string, object>> _lazyPropertyDictionary;

/// <summary>
/// The <see cref="T:Microsoft.Extensions.Logging.LogLevel"/> that the item was logged at.
/// </summary>
public LogLevel LogLevel { get; }

/// <summary>
/// An <see cref="T:Microsoft.Extensions.Logging.EventId"/> that identifies a logging event.
/// </summary>
public EventId EventId { get; }

/// <summary>
/// The entry to be written. Can be also an object.
/// </summary>
public object? State { get; }

/// <summary>
/// The <see cref="T:System.Exception"/> that was attached to the log.
/// </summary>
public Exception? Exception { get; }

/// <summary>
/// The formatted message.
/// </summary>
public string FormattedMessage { get; }

/// <summary>
/// The sequence number of the log message.
/// </summary>
/// <remarks>In a multi-threaded environment there may be gaps between adjacent log messages.</remarks>
/// <remarks>In a multithreaded environment there may be gaps between adjacent log messages.</remarks>
public int Sequence { get; }

/// <summary>
/// The time the log entry was created in UTC.
/// The time the log entry was created in UTC.
/// </summary>
public DateTime TimestampUtc { get; }

Expand All @@ -74,7 +82,7 @@ public DateTimeOffset TimestampLocal
/// </summary>
public IReadOnlyList<KeyValuePair<string, object>> Properties =>
State as IReadOnlyList<KeyValuePair<string, object>> ?? Array.Empty<KeyValuePair<string, object>>();

/// <summary>
/// The properties, if any, for the log entry.
/// </summary>
Expand All @@ -87,7 +95,7 @@ public DateTimeOffset TimestampLocal
(string) Properties
.FirstOrDefault(p => p.Key == OriginalMessagePropertyName)
.Value;

/// <summary>
/// The category name of the log entry, if available.
/// </summary>
Expand Down Expand Up @@ -178,4 +186,4 @@ public override string ToString()
}

private string DebuggerDisplayString => $"[#{Sequence} @ {TimestampLocal:HH:mm:ss.fff zzz} {LogLevel} {CategoryName}] {FormattedMessage}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<YEAR>$([System.DateTime]::Now.Year)</YEAR>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<Title>Stravaig Logging Capture for Tests</Title>
<Authors>Colin Angus Mackay</Authors>
<Copyright>©2020-$(YEAR) Colin Angus Mackay. See licence for more information.</Copyright>
Expand All @@ -19,10 +19,10 @@

Use version 1.x for .NET prior to 6.0.
Use version 2.x for .NET 6.0 onwards.
Use version 3.x for .NET 6.0 &amp; 8.0 onwards.
Use version 3.x for .NET 6.0, 8.0 &amp; 9.0 onwards.
</Description>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
<LangVersion>13</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Include="stravaig-icon.png" Pack="true" PackagePath="/" />
Expand Down Expand Up @@ -52,4 +52,9 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
</ItemGroup>

</Project>
22 changes: 13 additions & 9 deletions src/Stravaig.Extensions.Logging.Diagnostics/TestCaptureLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
#if NET9_0_OR_GREATER
using System.Threading;
#endif

namespace Stravaig.Extensions.Logging.Diagnostics;

Expand All @@ -11,16 +14,18 @@ namespace Stravaig.Extensions.Logging.Diagnostics;
/// </summary>
public class TestCaptureLogger : ITestCaptureLogger
{
private readonly List<LogEntry> _logs;
private readonly object _syncRoot;
private readonly List<LogEntry> _logs = [];
#if NET9_0_OR_GREATER
private readonly Lock _listGuard = new();
#else
private readonly object _listGuard = new object();
#endif

/// <summary>
/// Initialises a new instance of the <see cref="T:Stravaig.Extensions.Logging.Diagnostics.TestCaptureLogger"/> class.
/// </summary>
public TestCaptureLogger()
{
_logs = new List<LogEntry>();
_syncRoot = new object();
CategoryName = string.Empty;
}

Expand All @@ -29,7 +34,6 @@ public TestCaptureLogger()
/// </summary>
/// <param name="categoryName">The name of the category</param>
public TestCaptureLogger(string categoryName)
: this()
{
CategoryName = categoryName;
}
Expand All @@ -42,7 +46,7 @@ public TestCaptureLogger(string categoryName)
/// <inheritdoc />
public IReadOnlyList<LogEntry> GetLogs()
{
lock (_syncRoot)
lock (_listGuard)
{
_logs.Sort();
return _logs.ToArray();
Expand All @@ -52,7 +56,7 @@ public IReadOnlyList<LogEntry> GetLogs()
/// <inheritdoc />
public IReadOnlyList<LogEntry> GetLogs(Func<LogEntry, bool> predicate)
{
lock (_syncRoot)
lock (_listGuard)
{
return _logs
.Where(predicate)
Expand All @@ -78,7 +82,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
{
var formattedMessage = formatter(state, exception);
var logEntry = CreateLogEntry(logLevel, eventId, state, exception, formattedMessage);
lock (_syncRoot)
lock (_listGuard)
{
_logs.Add(logEntry);
}
Expand Down Expand Up @@ -131,7 +135,7 @@ public void Dispose()
/// <inheritdoc />
public void Reset()
{
lock (_syncRoot)
lock (_listGuard)
{
_logs.Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stravaig.Extensions.Logging.Diagnostics/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Stravaig Log Capture is a way to capture the logs in a test and examine them to

* v1.x: Supports .NET Core 3.1 & .NET 5
* v2.x: Supports .NET 6.0, 7.0 & 8.0
* v3.x: Supports .NET 6.0 & 8.0
* v3.x: Supports .NET 6.0, 8.0 & 9.0

## Why do I want to test my logs?

Expand Down