Browse Source

Add string ToRepr extension

pull/55/head
Ionite 1 year ago
parent
commit
86b2b280e5
No known key found for this signature in database
  1. 17
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 27
      StabilityMatrix.Core/Extensions/StringExtensions.cs
  3. 4
      StabilityMatrix.Core/Helper/ArchiveHelper.cs

17
StabilityMatrix.Avalonia/App.axaml.cs

@ -380,17 +380,24 @@ public sealed class App : Application
{ {
var logConfig = new LoggingConfiguration(); var logConfig = new LoggingConfiguration();
var fileTarget = new FileTarget("logfile") // File target
logConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal,
new FileTarget("logfile")
{ {
Layout = "${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}",
ArchiveOldFileOnStartup = true, ArchiveOldFileOnStartup = true,
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log", FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log",
ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log", ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log",
ArchiveNumbering = ArchiveNumberingMode.Rolling, ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 2 MaxArchiveFiles = 2
}; });
var debugTarget = new DebuggerTarget("debugger") {Layout = "${message}"};
logConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, fileTarget); // Debugger Target
logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, debugTarget); logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal,
new DebuggerTarget("debugger")
{
Layout = "${message}"
});
LogManager.Configuration = logConfig; LogManager.Configuration = logConfig;
// Add Sentry to NLog if enabled // Add Sentry to NLog if enabled

27
StabilityMatrix.Core/Extensions/StringExtensions.cs

@ -0,0 +1,27 @@
using System.CodeDom;
using System.CodeDom.Compiler;
namespace StabilityMatrix.Core.Extensions;
public static class StringExtensions
{
/// <summary>
/// Converts string to repr
/// </summary>
public static string ToRepr(this string str)
{
using var writer = new StringWriter();
using var provider = CodeDomProvider.CreateProvider("CSharp");
provider.GenerateCodeFromExpression(
new CodePrimitiveExpression(str),
writer,
new CodeGeneratorOptions {IndentString = "\t"});
var literal = writer.ToString();
// Replace split lines
literal = literal.Replace($"\" +{Environment.NewLine}\t\"", "");
return literal;
}
}

4
StabilityMatrix.Core/Helper/ArchiveHelper.cs

@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
using NLog; using NLog;
using SharpCompress.Common; using SharpCompress.Common;
using SharpCompress.Readers; using SharpCompress.Readers;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes; using StabilityMatrix.Core.Processes;
using Timer = System.Timers.Timer; using Timer = System.Timers.Timer;
@ -238,7 +239,8 @@ public static partial class ArchiveHelper
// Check if symbolic link // Check if symbolic link
if (entry.LinkTarget != null) if (entry.LinkTarget != null)
{ {
Logger.Debug($"Extracting symbolic link [{entry.Key}] ({outputPath} to {entry.LinkTarget})"); Logger.Debug($"Extracting symbolic link [{entry.Key.ToRepr()}] " +
$"({outputPath.ToRepr()} to {entry.LinkTarget.ToRepr()})");
// Try to write link, if fail, continue copy file // Try to write link, if fail, continue copy file
try try
{ {

Loading…
Cancel
Save