Skip to content

Commit

Permalink
make logger thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Jul 13, 2022
1 parent b101401 commit 03d4021
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
51 changes: 30 additions & 21 deletions TextureExtraction tool/Data/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum FileAction

internal class ScanLogger : IDisposable
{
private static readonly object LockFile = new object();

public string FullPath { get; private set; }

Expand Down Expand Up @@ -40,7 +41,10 @@ private void GenerateLogFullPath(string directory)

public void WriteLine(string value)
{
LogFile.WriteLine(value);
lock (LockFile)
{
LogFile.WriteLine(value);
}
}

private void WriteHeader()
Expand Down Expand Up @@ -69,32 +73,37 @@ public void WriteFoot(TextureExtractor.Result result)

public void WriteEX(Exception ex,in string strMessage = "")
{
LogFile.WriteLine("".PadLeft(64, '-'));
LogFile.WriteLine($"Error!!!... {strMessage} {ex?.Message}");
LogFile.WriteLine($"{ex?.Source}:{ex?.StackTrace}");
LogFile.WriteLine("".PadLeft(64, '-'));
Console.WriteLine("".PadLeft(64, '-'));
Console.WriteLine($"Error!!!... {strMessage} {ex?.Message}");
Console.WriteLine("".PadLeft(64, '-'));
lock (LockFile)
{
LogFile.WriteLine("".PadLeft(64, '-'));
LogFile.WriteLine($"Error!!!... {strMessage} {ex?.Message}");
LogFile.WriteLine($"{ex?.Source}:{ex?.StackTrace}");
LogFile.WriteLine("".PadLeft(64, '-'));
Console.WriteLine($"Error!!!... {strMessage} {ex?.Message}");
LogFile.Flush();
}
}

public void Write(FileAction action,in string file,in string value)
{
switch (action)
lock (LockFile)
{
case FileAction.Unknown:
LogFile.WriteLine("Unknown:");
break;
case FileAction.Unsupported:
LogFile.WriteLine("Unsupported:");
break;
case FileAction.Extract:
LogFile.WriteLine("Extract:");
break;
switch (action)
{
case FileAction.Unknown:
LogFile.WriteLine("Unknown:");
break;
case FileAction.Unsupported:
LogFile.WriteLine("Unsupported:");
break;
case FileAction.Extract:
LogFile.WriteLine("Extract:");
break;
}
LogFile.Write($"\"~{file}\"\n");
LogFile.WriteLine($" {value}");
LogFile.Flush();
}
LogFile.Write($"\"~{file}\"\n");
LogFile.WriteLine($" {value}");
LogFile.Flush();
}

#region Dispose
Expand Down
2 changes: 1 addition & 1 deletion TextureExtraction tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.4.0")]
[assembly: AssemblyVersion("0.6.4.1")]
[assembly: AssemblyFileVersion("0.6.4.0")]

0 comments on commit 03d4021

Please sign in to comment.