Skip to content
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

Increase amount of LogWriter options #596

Merged
merged 6 commits into from
Jul 15, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Right now, we are compatible with version 11. If you need to make changes, you c

Here are some things you can do to figure out how to get your app running:

* Make sure you have enabled and debugged your application thoroughly. A great way to do this is to set `SparkleUpdater.LogWriter = new LogWriter(true)` and then watch your console output while debugging.
* Make sure you have enabled and debugged your application thoroughly. A great way to do this is to set `SparkleUpdater.LogWriter = new LogWriter(LogWriterOutputMode.Console)` and then watch your console output while debugging.
* Look at the NetSparkleUpdater samples by downloading this repo and running the samples. You can even try putting your app cast URL in there and using your public key to debug with the source code!
* Ask for help in our [Gitter](https://gitter.im/NetSparkleUpdater/NetSparkle)
* Post an issue and wait for someone to respond with assistance
Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
* `AssemblyReflectionAccessor` has been deprecated. Please use `AsmResolverAccessor` instead. (#587)
* `AssemblyDiagnosticAccessor.AssemblyVersion` now returns `FileVersionInfo.GetVersionInfo(assemblyName).ProductVersion` rather than `FileVersionInfo.GetVersionInfo(assemblyName).FileVersion` so we can get semver versioning information
* For ed25519 use, changed from BouncyCastle to Chaos.NaCl (large file size savings and we don't need all of BouncyCastle's features). You can verify its use and code online here: https://github.com/NetSparkleUpdater/Chaos.NaCl. Additionally, this package is available on NuGet for your own projects.
* `LogWriter` has undergone several changes:
* `public static string tag = "netsparkle:";` has changed to `public string Tag { get; set; } = "netsparkle:";`
* Instead of a simple `bool` to control printing to `Trace.WriteLine` or `Console.WriteLine`, there is now a new enum, `NetSparkleUpdater.Enums.LogWriterOutputMode`, which you can use to control whether `LogWriter` outputs to `Console`, `Trace`, `Debug`, or to `None` (don't output at all).
* Removed `PrintDiagnosticToConsole` property and replaced it with `OutputMode` of type `LogWriterOutputMode`.
* The default print mode for `LogWriter` is still `Trace` by default, as it was in prior versions.
* By default, timestamps are now output along with the `Tag` and actual log item

**Changes/Fixes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<files>
<file src="..\..\README.md" target="" />
<file src="..\..\LICENSE.md" target="" />
<file src="..\..\src\NetSparkle\ArtWork\software-update-available.png" target="" />
</files>
</package>
4 changes: 2 additions & 2 deletions src/NetSparkle.Samples.Avalonia.MacOS/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using NetSparkleUpdater.Enums;
using NetSparkleUpdater.SignatureVerifiers;
using NetSparkleUpdater.UI.Avalonia;
using System.IO;

namespace NetSparkleUpdater.Samples.Avalonia
Expand All @@ -23,7 +23,7 @@ public MainWindow()
UIFactory = new NetSparkleUpdater.UI.Avalonia.UIFactory(Icon),
// Avalonia version doesn't support separate threads: https://github.com/AvaloniaUI/Avalonia/issues/3434#issuecomment-573446972
ShowsUIOnMainThread = true,
LogWriter = new LogWriter(true)
LogWriter = new LogWriter(LogWriterOutputMode.Console)
//UseNotificationToast = false // Avalonia version doesn't yet support notification toast messages
};
// TLS 1.2 required by GitHub (https://developer.github.com/changes/2018-02-01-weak-crypto-removal-notice/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public MainWindow()
UIFactory = new NetSparkleUpdater.UI.Avalonia.UIFactory(Icon),
// Avalonia version doesn't support separate threads: https://github.com/AvaloniaUI/Avalonia/issues/3434#issuecomment-573446972
ShowsUIOnMainThread = true,
LogWriter = new LogWriter(true),
LogWriter = new LogWriter(),
RelaunchAfterUpdate = true,
//UseNotificationToast = false // Avalonia version doesn't yet support notification toast messages

Expand Down
10 changes: 3 additions & 7 deletions src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using NetSparkleUpdater.AppCastGenerator;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using NetSparkleUpdater.Enums;
using Org.BouncyCastle.Security;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using Xunit;
using System.Runtime.InteropServices;
using System.Diagnostics;
Expand Down Expand Up @@ -771,7 +767,7 @@ public void NetSparkleCanParseHumanReadableAppCast()
new NetSparkleUpdater.SignatureVerifiers.Ed25519Checker(
NetSparkleUpdater.Enums.SecurityMode.Strict,
publicKeyString),
new NetSparkleUpdater.LogWriter(true));
new NetSparkleUpdater.LogWriter(LogWriterOutputMode.Console));
var didSucceed = appCastHandler.DownloadAndParse();
Assert.True(didSucceed);
var updates = appCastHandler.GetAvailableUpdates();
Expand Down Expand Up @@ -938,7 +934,7 @@ public void CanSetCriticalVersion()
new NetSparkleUpdater.SignatureVerifiers.Ed25519Checker(
NetSparkleUpdater.Enums.SecurityMode.Strict,
publicKeyString),
new NetSparkleUpdater.LogWriter(true));
new NetSparkleUpdater.LogWriter(LogWriterOutputMode.Console));
var didSucceed = appCastHandler.DownloadAndParse();
Assert.True(didSucceed);
var updates = appCastHandler.GetAvailableUpdates();
Expand Down
3 changes: 2 additions & 1 deletion src/NetSparkle.Tools.AppCastGenerator/XMLAppCastMaker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NetSparkleUpdater.AppCastHandlers;
using NetSparkleUpdater.Enums;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -56,7 +57,7 @@ public override (List<AppCastItem>, string) GetItemsAndProductNameFromExistingAp
}

var docDescendants = doc.Descendants("item");
var logWriter = new LogWriter(true);
var logWriter = new LogWriter(LogWriterOutputMode.Console);
foreach (var item in docDescendants)
{
var currentItem = AppCastItem.Parse("", "", "/", item, logWriter);
Expand Down
28 changes: 28 additions & 0 deletions src/NetSparkle/Enums/LogWriterOutputMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics;

namespace NetSparkleUpdater.Enums
{
/// <summary>
/// Output mode for the <seealso cref="LogWriter"/> class
/// </summary>
public enum LogWriterOutputMode
{
/// <summary>
/// Don't output anything
/// </summary>
None = 0,
/// <summary>
/// Output to <seealso cref="Console.WriteLine(string, object[])"/>
/// </summary>
Console = 1,
/// <summary>
/// Output to <seealso cref="Trace.WriteLine(string)"/>
/// </summary>
Trace = 2,
/// <summary>
/// Output to <seealso cref="Debug.WriteLine(string, object[])"/>
/// </summary>
Debug = 3
}
}
52 changes: 27 additions & 25 deletions src/NetSparkle/LogWriter.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
using NetSparkleUpdater.Enums;
using NetSparkleUpdater.Interfaces;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetSparkleUpdater
{
/// <summary>
/// A simple class to handle log information for NetSparkleUpdater.
/// A simple class to handle logging information.
/// Make sure to do any setup for this class that you want
/// to do before calling StartLoop on your <see cref="SparkleUpdater"/> object.
/// </summary>
public class LogWriter : ILogger
{
/// <summary>
/// Tag to show before any log statements
/// Tag to show before any log statements. Can be set to null.
/// </summary>
public static string tag = "netsparkle:";
public string Tag { get; set; } = "netsparkle:";

/// <summary>
/// Empty constructor -> sets PrintDiagnosticToConsole to false
/// Create a LogWriter that outputs to <seealso cref="Trace.WriteLine(string)"/> by default
/// </summary>
public LogWriter()
{
PrintDiagnosticToConsole = false;
OutputMode = LogWriterOutputMode.Trace;
}

/// <summary>
/// LogWriter constructor that takes a bool to determine
/// the value for printDiagnosticToConsole
/// Create a LogWriter that outputs via the given LogWriterOutputMode mode
/// </summary>
/// <param name="printDiagnosticToConsole">False to print to <seealso cref="Trace.WriteLine(string)"/>;
/// true to print to <seealso cref="Console.WriteLine(string)"/></param>
public LogWriter(bool printDiagnosticToConsole)
/// <param name="outputMode"><seealso cref="LogWriterOutputMode"/> for this LogWriter instance</param>;
public LogWriter(LogWriterOutputMode outputMode)
{
PrintDiagnosticToConsole = printDiagnosticToConsole;
OutputMode = outputMode;
}

#region Properties

/// <summary>
/// True if this class should print to <seealso cref="Console.WriteLine(string)"/>;
/// false if this object should print to <seealso cref="Trace.WriteLine(string)"/>.
/// Defaults to false.
/// <seealso cref="LogWriterOutputMode"/> for this LogWriter instance. Set to
/// <seealso cref="LogWriterOutputMode.None"/> to make this LogWriter output nothing.
/// </summary>
public bool PrintDiagnosticToConsole { get; set; }
public LogWriterOutputMode OutputMode { get; set; }

#endregion

/// <inheritdoc/>
public virtual void PrintMessage(string message, params object[] arguments)
{
if (PrintDiagnosticToConsole)
var timestamp = string.Format("[{0:s}]", DateTime.Now);
switch (OutputMode)
{
Console.WriteLine(tag + " " + message, arguments);
}
else
{
Trace.WriteLine(string.Format(tag + " " + message, arguments));
case LogWriterOutputMode.Console:
Console.WriteLine(timestamp + " " + Tag + (string.IsNullOrWhiteSpace(Tag) ? "" : " ") + message, arguments);
break;
case LogWriterOutputMode.Trace:
Trace.WriteLine(string.Format(timestamp + " " + Tag + (string.IsNullOrWhiteSpace(Tag) ? "" : " ") + message, arguments));
break;
case LogWriterOutputMode.Debug:
Debug.WriteLine(timestamp + " " + Tag + (string.IsNullOrWhiteSpace(Tag) ? "" : " ") + message, arguments);
break;
case LogWriterOutputMode.None:
break;
default:
break;
}
}
}
Expand Down
Loading