Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 342231c

Browse files
committed
Revert back to using net472 for tests in the short term. XUnit console runner doesn't support .NET Core 3.1 and makes it difficult to implement the logging factory under .NET Core 2.1. Hoping to multi-target - will investigate running tests via Visual Studio runner if possible.
1 parent bdf966c commit 342231c

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

tests/MMALSharp.Tests/MMALFixture.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System;
77
using System.IO;
88
using System.Linq;
9+
using Microsoft.Extensions.Logging;
10+
using MMALSharp.Common.Utility;
11+
using NLog.Extensions.Logging;
912
using Xunit;
1013

1114
namespace MMALSharp.Tests
@@ -17,6 +20,16 @@ public class MMALFixture : IDisposable
1720

1821
public MMALFixture()
1922
{
23+
var loggerFactory = LoggerFactory.Create(builder =>
24+
{
25+
26+
builder
27+
.ClearProviders()
28+
.SetMinimumLevel(LogLevel.Trace)
29+
.AddNLog("NLog.config");
30+
});
31+
32+
MMALLog.LoggerFactory = loggerFactory;
2033
}
2134

2235
public void CheckAndAssertFilepath(string filepath)

tests/MMALSharp.Tests/MMALSharp.Tests.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
3+
<!--<OutputType>Exe</OutputType>-->
44
<AssemblyTitle>MMALSharp.Tests</AssemblyTitle>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<TargetFramework>net472</TargetFramework>
66
<IsPackable>false</IsPackable>
77
<AssemblyName>MMALSharp.Tests</AssemblyName>
88
<PackageId>MMALSharp.Tests</PackageId>
@@ -15,7 +15,9 @@
1515
<Folder Include="Properties\" />
1616
</ItemGroup>
1717
<ItemGroup>
18+
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
1819
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
20+
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
1921
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
2022
<PrivateAssets>All</PrivateAssets>
2123
</PackageReference>
@@ -34,6 +36,9 @@
3436
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
3537
</ItemGroup>
3638
<ItemGroup>
39+
<None Update="NLog.config">
40+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
41+
</None>
3742
<None Update="xunit.runner.json">
3843
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3944
</None>

tests/MMALSharp.Tests/NLog.config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
3+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
autoReload="true"
6+
internalLogFile="${basedir}/console-example-internal.log"
7+
internalLogLevel="Info" >
8+
9+
<!-- the targets to write to -->
10+
<targets>
11+
<!-- write logs to file -->
12+
<target xsi:type="File" name="target1" fileName="${basedir}/mmal-log-${shortdate}.log"
13+
layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />
14+
<target xsi:type="Console" name="target2"
15+
layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />
16+
</targets>
17+
18+
<!-- rules to map from logger name to target -->
19+
<rules>
20+
<logger name="*" minlevel="Trace" writeTo="target1" />
21+
<logger name="*" minlevel="Info" writeTo="target2" />
22+
</rules>
23+
</nlog>

0 commit comments

Comments
 (0)