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. 29
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 27
      StabilityMatrix.Core/Extensions/StringExtensions.cs
  3. 4
      StabilityMatrix.Core/Helper/ArchiveHelper.cs

29
StabilityMatrix.Avalonia/App.axaml.cs

@ -380,17 +380,24 @@ public sealed class App : Application
{
var logConfig = new LoggingConfiguration();
var fileTarget = new FileTarget("logfile")
{
ArchiveOldFileOnStartup = true,
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log",
ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log",
ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 2
};
var debugTarget = new DebuggerTarget("debugger") {Layout = "${message}"};
logConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, fileTarget);
logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, debugTarget);
// File target
logConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal,
new FileTarget("logfile")
{
Layout = "${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}",
ArchiveOldFileOnStartup = true,
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log",
ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log",
ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 2
});
// Debugger Target
logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal,
new DebuggerTarget("debugger")
{
Layout = "${message}"
});
LogManager.Configuration = logConfig;
// 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 SharpCompress.Common;
using SharpCompress.Readers;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
using Timer = System.Timers.Timer;
@ -238,7 +239,8 @@ public static partial class ArchiveHelper
// Check if symbolic link
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
{

Loading…
Cancel
Save