Merge pull request #3023 from ZakFahey/logwriter
Lazy initialize TextLog._logWriter
This commit is contained in:
commit
787fe923c2
2 changed files with 12 additions and 3 deletions
|
|
@ -29,7 +29,8 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TextLog : ILog, IDisposable
|
public class TextLog : ILog, IDisposable
|
||||||
{
|
{
|
||||||
private readonly StreamWriter _logWriter;
|
private readonly bool ClearFile;
|
||||||
|
private StreamWriter _logWriter;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File name of the Text log
|
/// File name of the Text log
|
||||||
|
|
@ -44,7 +45,7 @@ namespace TShockAPI
|
||||||
public TextLog(string filename, bool clear)
|
public TextLog(string filename, bool clear)
|
||||||
{
|
{
|
||||||
FileName = filename;
|
FileName = filename;
|
||||||
_logWriter = new StreamWriter(filename, !clear);
|
ClearFile = clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MayWriteType(TraceLevel type)
|
public bool MayWriteType(TraceLevel type)
|
||||||
|
|
@ -247,6 +248,10 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (!MayWriteType(level))
|
if (!MayWriteType(level))
|
||||||
return;
|
return;
|
||||||
|
if (_logWriter is null)
|
||||||
|
{
|
||||||
|
_logWriter = new StreamWriter(FileName, !ClearFile);
|
||||||
|
}
|
||||||
|
|
||||||
var caller = "TShock";
|
var caller = "TShock";
|
||||||
|
|
||||||
|
|
@ -278,7 +283,10 @@ namespace TShockAPI
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_logWriter.Dispose();
|
if (_logWriter != null)
|
||||||
|
{
|
||||||
|
_logWriter.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
|
||||||
* Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace)
|
* Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace)
|
||||||
* Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace)
|
* Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace)
|
||||||
* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace)
|
* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace)
|
||||||
|
* Fixed bug where when the `UseSqlLogs` config property is true, an empty log file would still get created. (@ZakFahey)
|
||||||
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)
|
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)
|
||||||
* Rewrote the `.dockerignore` file into a denylist. (@timschumi)
|
* Rewrote the `.dockerignore` file into a denylist. (@timschumi)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue