Skip to content

AWSTarget updated to NLog v5.2.2 for build trimming #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Jun 5, 2025

NLog v5.2.2 supports build-trimming without build-warnings (enabled by default with .NET7 and newer)

NLog v5.2.2 was released 7th April 2023, so little over 2 years old.

See also: #225

@GarrettBeatty
Copy link
Contributor

Total time: 1.0885 Seconds
  1:15>Project "/codebuild/output/src2109165532/src/github.com/aws/***/test/AWS.Logger.NLog.FilterTests/AWS.Logger.NLog.FilterTests.csproj" (1:15) is building "/codebuild/output/src2109165532/src/github.com/aws/***/test/AWS.Logger.NLog.FilterTests/AWS.Logger.NLog.FilterTests.csproj" (1:18) on node 6 (VSTest target(s)).
     1>_VSTestConsole:
         MSB4181: The "VSTestTask" task returned false but did not log an error.
     1>Done Building Project "/codebuild/output/src2109165532/src/github.com/aws/***/test/AWS.Logger.NLog.FilterTests/AWS.Logger.NLog.FilterTests.csproj" (VSTest target(s)) -- FAILED.
     1>DispatchToInnerBuildsWithVSTestTarget:
         Build continuing because "ContinueOnError" on the task "MSBuild" is set to "ErrorAndContinue".
Test run for /codebuild/output/src2109165532/src/github.com/aws/***/test/AWS.Logger.NLog.FilterTests/bin/Release/net472/AWS.Logger.NLog.FilterTests.dll (.NETFramework,Version=v4.7.2)
VSTest version 17.11.1 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.5.3.1+6b60a9e56a (64-bit Mono 6.12.0.107 (tarball Wed Dec  9 21:44:58 UTC 2020))
[xUnit.net 00:00:00.43]   Discovering: AWS.Logger.NLog.FilterTests
[xUnit.net 00:00:00.54]   Discovered:  AWS.Logger.NLog.FilterTests
[xUnit.net 00:00:00.55]   Starting:    AWS.Logger.NLog.FilterTests
[xUnit.net 00:00:00.72]     AWS.Logger.NLogger.FilterTests.TestFilter.CustomFilter [FAIL]
[xUnit.net 00:00:00.72]       Assert.Single() Failure: The collection was empty
[xUnit.net 00:00:00.72]       Stack Trace:
[xUnit.net 00:00:00.73]           at AWS.Logger.NLogger.FilterTests.TestFilter.CustomFilter () [0x0009d] in <76ad61cf3900414e94f526449ef93428>:0
[xUnit.net 00:00:00.73]           at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
[xUnit.net 00:00:00.73]           at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <5dfd69ae4e3b402db546d8ded6fc755e>:0
[xUnit.net 00:00:01.01]   Finished:    AWS.Logger.NLog.FilterTests
  Failed AWS.Logger.NLogger.FilterTests.TestFilter.CustomFilter [86 ms]
  Error Message:
   Assert.Single() Failure: The collection was empty
  Stack Trace:

i ran the branch in the pipeline but looks like this test is failing. are you able to take a look?

@snakefoot
Copy link
Contributor Author

snakefoot commented Jun 5, 2025

Yes NLog v5 introduced a breaking change when using NLog filters, because users was often confused that filters had no effect:

See also: LoggingRule Filters DefaultAction changed to FilterResult.Ignore

@GarrettBeatty
Copy link
Contributor

GarrettBeatty commented Jun 5, 2025

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.5.3.1+6b60a9e56a (64-bit Mono 6.12.0.107 (tarball Wed Dec  9 21:44:58 UTC 2020))
[xUnit.net 00:00:00.44]   Discovering: AWS.Logger.Log4Net.Tests
[xUnit.net 00:00:00.54]   Discovered:  AWS.Logger.Log4Net.Tests
[xUnit.net 00:00:00.55]   Starting:    AWS.Logger.Log4Net.Tests
  Passed AWS.Logger.Log4Net.Tests.Log4NetTestClass.MultiThreadBufferFullTest [24 s]
  Passed AWS.Logger.Log4Net.Tests.Log4NetTestClass.MultiThreadTest [6 s]
[xUnit.net 00:00:39.56]     AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net [FAIL]
[xUnit.net 00:00:39.56]       System.NullReferenceException : Object reference not set to an instance of an object
[xUnit.net 00:00:39.56]       Stack Trace:
[xUnit.net 00:00:39.57]           at AWS.Logger.TestUtils.BaseTestClass.SimpleLoggingTest (System.String logGroupName) [0x0026f] in <03ea80cc999c483aa40898d90e2298ba>:0
[xUnit.net 00:00:39.57]           at AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net () [0x000aa] in <19c92fa4bef44e01806fd3a444598bdc>:0
  Failed AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net [7 s]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object
  Stack Trace:
    at AWS.Logger.TestUtils.BaseTestClass.SimpleLoggingTest (System.String logGroupName) [0x0026f] in <03ea80cc999c483aa40898d90e2298ba>:0
  at AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net () [0x000aa] in <19c92fa4bef44e01806fd3a444598bdc>:0
[xUnit.net 00:00:46.23]   Finished:    AWS.Logger.Log4Net.Tests
  Passed AWS.Logger.Log4Net.Tests.Log4NetTestClass.CustomLogStreamNameTest [6 s]
Results File: /codebuild/output/src1560369023/src/github.com/aws/***/testresults/_500326257dd1_2025-06-05_14_54_58.trx

Test Run Failed.
Total tests: 4
     Passed: 3
     Failed: 1
 Total time: 46.7846 Seconds
  1:15>Project "/codebuild/output/src1560369023/src/github.com/aws/***/test/AWS.Logger.Log4Net.Tests/AWS.Logger.Log4Net.Tests.csproj" (1:15) is building "/codebuild/output/src1560369023/src/github.com/aws/***/test/AWS.Logger.Log4Net.Tests/AWS.Logger.Log4Net.Tests.csproj" (1:19) on node 6 (VSTest target(s)).
     1>_VSTestConsole:
         MSB4181: The "VSTestTask" task returned false but did not log an error.
     1>Done Building Project "/codebuild/output/src1560369023/src/github.com/aws/***/test/AWS.Logger.Log4Net.Tests/AWS.Logger.Log4Net.Tests.csproj" (VSTest target(s)) -- FAILED.
     1>DispatchToInnerBuildsWithVSTestTarget:
         Build continuing because "ContinueOnError" on the task "MSBuild" is set to "ErrorAndContinue".
     1>Done Building Project "/codebuild/output/src1560369023/src/github.com/aws/***/test/AWS.Logger.Log4Net.Tests/AWS.Logger.Log4Net.Tests.csproj" (VSTest target(s)) -- FAILED.

Build FAILED.
    0 Warning(s)
    0 Error(s)

looks like there is a couple more errors.

My only concern with this change if users of aws logging dotnet will have to make any changes on their end to make things work with the new version of nlog. ill have to test manually as well to verify.

Edit: I tested manually with the sampleapps and didnt notice any major issues. I can see logs being printed out and still sent to aws cloudwatch @philasmar is there anything else we should be looking for?

@snakefoot
Copy link
Contributor Author

snakefoot commented Jun 6, 2025

This looks like log4net and not NLog:

[xUnit.net 00:00:39.56]     AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net [FAIL]
[xUnit.net 00:00:39.56]       System.NullReferenceException : Object reference not set to an instance of an object
[xUnit.net 00:00:39.56]       Stack Trace:
[xUnit.net 00:00:39.57]           at AWS.Logger.TestUtils.BaseTestClass.SimpleLoggingTest (System.String logGroupName) [0x0026f] in <03ea80cc999c483aa40898d90e2298ba>:0
[xUnit.net 00:00:39.57]           at AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net () [0x000aa] in <19c92fa4bef44e01806fd3a444598bdc>:0
  Failed AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net [7 s]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object
  Stack Trace:
    at AWS.Logger.TestUtils.BaseTestClass.SimpleLoggingTest (System.String logGroupName) [0x0026f] in <03ea80cc999c483aa40898d90e2298ba>:0
  at AWS.Logger.Log4Net.Tests.Log4NetTestClass.Log4Net () [0x000aa] in <19c92fa4bef44e01806fd3a444598bdc>:0
[xUnit.net 00:00:46.23]   Finished:    AWS.Logger.Log4Net.Tests

NLog v5 includes a few major breaking changes, where the "worst" one is the change in NLog Filter-default-behavior. And the other one is that NLog extensions must to explicitly loaded:

  <extensions>
    <add assembly="NLog.AWS.Logger" />
  </extensions>

@GarrettBeatty GarrettBeatty requested a review from normj June 12, 2025 00:19
@GarrettBeatty
Copy link
Contributor

@philasmar @normj can you review this? I wasn't sure if we need to make the change a minor instead of patch or major?

Copy link
Contributor

@philasmar philasmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to add some NativeAOT tests for the trimming support you added?

@snakefoot
Copy link
Contributor Author

snakefoot commented Jun 16, 2025

@philasmar Are you able to add some NativeAOT tests for the trimming support you added?

NativeAOT is not supported by NLog v5, but planning to include AOT-support with NLog v6:

Notice build-trimming and NativeAOT are two different features.

"Projects": [
{
"Name": "NLog.AWS.Logger",
"Type": "Major",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ive updated this to be major as per @normj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants