mirror of
https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities.git
synced 2026-09-04 09:06:31 +02:00
Fix exception when writing multiple logs at the same time
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
<RootNamespace>Stone_Red_C_Sharp_Utilities_Test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
namespace Stone_Red_C_Sharp_Utilities.Logging
|
||||
using System;
|
||||
|
||||
namespace Stone_Red_C_Sharp_Utilities.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the target of the log message.
|
||||
/// </summary>
|
||||
[System.Flags]
|
||||
[Flags]
|
||||
public enum LogTarget
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -85,11 +85,15 @@ namespace Stone_Red_C_Sharp_Utilities.Logging
|
||||
public void ClearLogFile(LogSeverity logSeverity)
|
||||
{
|
||||
OutputConfig outputConfig = GetOutputConfig(logSeverity);
|
||||
|
||||
lock (outputConfig)
|
||||
{
|
||||
if (File.Exists(outputConfig.FilePath))
|
||||
{
|
||||
File.WriteAllText(outputConfig.FilePath, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteLog(string message, string source, LogSeverity logSeverity, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
|
||||
{
|
||||
@@ -111,6 +115,8 @@ namespace Stone_Red_C_Sharp_Utilities.Logging
|
||||
Trace.WriteLine(debugOutput);
|
||||
}
|
||||
|
||||
lock (outputConfig)
|
||||
{
|
||||
if ((outputConfig.LogTarget & LogTarget.File) == LogTarget.File)
|
||||
{
|
||||
if (!File.Exists(outputConfig.FilePath))
|
||||
@@ -121,6 +127,7 @@ namespace Stone_Red_C_Sharp_Utilities.Logging
|
||||
File.AppendAllLines(outputConfig.FilePath, new[] { fileOutput });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OutputConfig GetOutputConfig(LogSeverity logSeverity)
|
||||
{
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<AssemblyVersion>1.0.3.1</AssemblyVersion>
|
||||
<FileVersion>1.0.3.1</FileVersion>
|
||||
<Version>1.0.3.1</Version>
|
||||
<AssemblyVersion>1.0.3.2</AssemblyVersion>
|
||||
<FileVersion>1.0.3.2</FileVersion>
|
||||
<Version>1.0.3.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
|
||||
Reference in New Issue
Block a user