Skip to content

Commit 6e7c296

Browse files
authored
NLog v6 RTM (#33)
1 parent 94af31c commit 6e7c296

File tree

11 files changed

+45
-61
lines changed

11 files changed

+45
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NLog Target for debugging on MAUI / Xamarin Mobile Platforms:
1919

2020
```xml
2121
<PackageReference Include="NLog.Targets.MauiLog" Version="8.*" />
22-
<PackageReference Include="NLog.Extensions.Logging" Version="5.*" />
22+
<PackageReference Include="NLog.Extensions.Logging" Version="6.*" />
2323
```
2424

2525
2) **Add NLog to the MauiApp**

appveyor.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
version: 6.0.0.{build}
2-
image: Visual Studio 2022
2+
image: Previous Visual Studio 2022
33
configuration: Release
44
platform: Any CPU
55
nuget:
66
disable_publish_on_pr: true
77
build_script:
88
- ps: dotnet tool install -g Redth.Net.Maui.Check
99
- ps: ./update-global-json.ps1 7.0.100
10-
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net7.0;net7.0-ios;net7.0-macos;net7.0-android;net7.0-maccatalyst"' /p:VersionPrefix=7.0.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
10+
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net7.0;net7.0-ios;net7.0-macos;net7.0-android;net7.0-maccatalyst"' /p:VersionPrefix=7.6.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
1111
- ps: ./update-global-json.ps1 6.0.100
12-
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net6.0;net6.0-ios;net6.0-macos;net6.0-android;net6.0-maccatalyst"' /p:VersionPrefix=6.0.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
12+
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net6.0;net6.0-ios;net6.0-macos;net6.0-android;net6.0-maccatalyst"' /p:VersionPrefix=6.6.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
1313
- ps: ./update-global-json.ps1 8.0.100
14-
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net8.0;net8.0-ios;net8.0-macos;net8.0-android;net8.0-maccatalyst"' /p:VersionPrefix=8.0.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
15-
- ps: dotnet build -c Release -p:VersionPrefix=8.0.0
14+
- ps: msbuild src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj /t:restore,pack /p:targetFrameworks='"net8.0;net8.0-ios;net8.0-macos;net8.0-android;net8.0-maccatalyst"' /p:VersionPrefix=8.6.0 /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal
15+
- ps: dotnet build -c Release -p:VersionPrefix=8.6.0
1616
artifacts:
1717
- path: '**\NLog.*.nupkg'
1818
- path: '**\NLog.*.snupkg'

examples/MauiApp2/MauiApp2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</ItemGroup>
6666

6767
<ItemGroup>
68-
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
68+
<PackageReference Include="NLog.Extensions.Logging" Version="6.0.0" />
6969
<ProjectReference Include="..\..\src\NLog.Targets.MauiLog\NLog.Targets.MauiLog.csproj" />
7070
</ItemGroup>
7171
</Project>

src/NLog.Targets.MauiLog/AndroidUtilLogTarget.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,55 @@ protected override void Write(LogEventInfo logEvent)
6565
private void DebugWriteLine(Layout layout, LogEventInfo logEvent)
6666
{
6767
var message = RenderLogEvent(layout, logEvent) ?? string.Empty;
68-
var category = RenderLogEvent(Category, logEvent);
69-
if (string.IsNullOrEmpty(category))
70-
category = null;
68+
var category = RenderLogEvent(Category, logEvent) ?? string.Empty;
7169

72-
Java.Lang.Throwable throwable = null;
70+
Java.Lang.Throwable? throwable = null;
7371
if (logEvent.Exception != null)
7472
{
7573
throwable = Java.Lang.Throwable.FromException(logEvent.Exception);
7674
}
7775

7876
if (logEvent.Level == LogLevel.Trace)
7977
{
80-
Android.Util.Log.Verbose(category, throwable, message);
78+
if (throwable is null)
79+
Android.Util.Log.Verbose(category, message);
80+
else
81+
Android.Util.Log.Verbose(category, throwable, message);
8182
}
8283
else if (logEvent.Level == LogLevel.Debug)
8384
{
84-
Android.Util.Log.Debug(category, throwable, message);
85+
if (throwable is null)
86+
Android.Util.Log.Debug(category, message);
87+
else
88+
Android.Util.Log.Debug(category, throwable, message);
8589
}
8690
else if (logEvent.Level == LogLevel.Info)
8791
{
88-
Android.Util.Log.Info(category, throwable, message);
92+
if (throwable is null)
93+
Android.Util.Log.Info(category, message);
94+
else
95+
Android.Util.Log.Info(category, throwable, message);
8996
}
9097
else if (logEvent.Level == LogLevel.Warn)
9198
{
92-
Android.Util.Log.Warn(category, throwable, message);
99+
if (throwable is null)
100+
Android.Util.Log.Warn(category, message);
101+
else
102+
Android.Util.Log.Warn(category, throwable, message);
93103
}
94104
else if (logEvent.Level == LogLevel.Error)
95105
{
96-
Android.Util.Log.Error(category, throwable, message);
106+
if (throwable is null)
107+
Android.Util.Log.Error(category, message);
108+
else
109+
Android.Util.Log.Error(category, throwable, message);
97110
}
98111
else
99112
{
100-
Android.Util.Log.Wtf(category, throwable, message);
113+
if (throwable is null)
114+
Android.Util.Log.Wtf(category, message);
115+
else
116+
Android.Util.Log.Wtf(category, throwable, message);
101117
}
102118
}
103119
}

src/NLog.Targets.MauiLog/AppleOSLogTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AppleOSLogTarget : TargetWithLayoutHeaderAndFooter
1717
/// <summary>
1818
/// Not used at the moment
1919
/// </summary>
20-
public Layout Category { get; set; }
20+
public Layout? Category { get; set; }
2121

2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="AppleOSLogTarget"/> class.

src/NLog.Targets.MauiLog/Config/SetupLoadConfigurationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class SetupLoadConfigurationExtensions
1515
/// <param name="configBuilder"></param>
1616
/// <param name="layout">Override the default Layout for output</param>
1717
/// <param name="category">Override the logging category</param>
18-
public static ISetupConfigurationTargetBuilder WriteToMauiLog(this ISetupConfigurationTargetBuilder configBuilder, Layout layout = null, Layout category = null)
18+
public static ISetupConfigurationTargetBuilder WriteToMauiLog(this ISetupConfigurationTargetBuilder configBuilder, Layout? layout = null, Layout? category = null)
1919
{
2020
#if __ANDROID__
2121
var logTarget = new AndroidUtilLogTarget();
@@ -38,7 +38,7 @@ public static ISetupConfigurationTargetBuilder WriteToMauiLog(this ISetupConfigu
3838
/// <param name="layout">Override the default Layout for output</param>
3939
/// <param name="category">Override the logging category</param>
4040
[System.Diagnostics.Conditional("DEBUG")]
41-
public static void WriteToMauiLogConditional(this ISetupConfigurationTargetBuilder configBuilder, Layout layout = null, Layout category = null)
41+
public static void WriteToMauiLogConditional(this ISetupConfigurationTargetBuilder configBuilder, Layout? layout = null, Layout? category = null)
4242
{
4343
configBuilder.WriteToMauiLog(layout, category);
4444
}

src/NLog.Targets.MauiLog/ILLink.Descriptors.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/NLog.Targets.MauiLog/Internal/MauiExceptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace NLog.Targets.MauiLog
2727
internal static class MauiExceptions
2828
{
2929
// We'll route all unhandled exceptions through this one event.
30-
public static event UnhandledExceptionEventHandler UnhandledException;
30+
public static event UnhandledExceptionEventHandler? UnhandledException;
3131

3232
static MauiExceptions()
3333
{
@@ -61,7 +61,9 @@ static MauiExceptions()
6161

6262
Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
6363
{
64+
#pragma warning disable CS8604 // Possible null reference argument for parameter 'sender'
6465
UnhandledException?.Invoke(sender, new UnhandledExceptionEventArgs(args.Exception, true));
66+
#pragma warning restore CS8604 // Possible null reference argument for parameter 'sender'
6567
};
6668
#endif
6769
}

src/NLog.Targets.MauiLog/Internal/PreserveAttribute.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/NLog.Targets.MauiLog/NLog.Targets.MauiLog.csproj

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
2020
<PackageReleaseNotes>
21-
- Removed static assembly version
21+
- Updated to NLog v6 with AOT-support
2222

2323
See https://github.com/NLog/NLog.Targets.MauiLog for documentation of NLog targets for MAUI
2424
</PackageReleaseNotes>
@@ -27,19 +27,14 @@ See https://github.com/NLog/NLog.Targets.MauiLog for documentation of NLog targe
2727
<IsPublishable>false</IsPublishable>
2828
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2929
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
30-
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
31-
<IsTrimmable>true</IsTrimmable>
32-
<TrimMode>copyused</TrimMode>
30+
<Nullable>enable</Nullable>
3331
<CheckEolWorkloads>false</CheckEolWorkloads>
3432
<SingleProject>true</SingleProject>
33+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
34+
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
35+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
3536
</PropertyGroup>
3637

37-
<ItemGroup>
38-
<EmbeddedResource Include="ILLink.Descriptors.xml">
39-
<LogicalName>ILLink.Descriptors.xml</LogicalName>
40-
</EmbeddedResource>
41-
</ItemGroup>
42-
4338
<ItemGroup>
4439
<None Include="../../README.md" Pack="true" PackagePath="" />
4540
<None Include="N.png" Pack="true" PackagePath="" Visible="false" />
@@ -65,7 +60,7 @@ See https://github.com/NLog/NLog.Targets.MauiLog for documentation of NLog targe
6560
</PropertyGroup>
6661

6762
<ItemGroup>
68-
<PackageReference Include="NLog" Version="5.2.2" />
63+
<PackageReference Include="NLog" Version="6.0.0" />
6964
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
7065
</ItemGroup>
7166

0 commit comments

Comments
 (0)