mirror of
https://github.com/Ellpeck/ExtremelySimpleLogger.git
synced 2024-11-22 10:03:29 +01:00
lock FileSink and StringSink
This commit is contained in:
parent
a17ebd37ad
commit
b989e6d541
2 changed files with 21 additions and 10 deletions
|
@ -51,6 +51,7 @@ namespace ExtremelySimpleLogger {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="s">The message to log</param>
|
/// <param name="s">The message to log</param>
|
||||||
public override void Log(string s) {
|
public override void Log(string s) {
|
||||||
|
lock (this.file) {
|
||||||
if (this.reopenOnWrite) {
|
if (this.reopenOnWrite) {
|
||||||
using (var w = this.file.AppendText())
|
using (var w = this.file.AppendText())
|
||||||
w.WriteLine(s);
|
w.WriteLine(s);
|
||||||
|
@ -58,15 +59,18 @@ namespace ExtremelySimpleLogger {
|
||||||
this.writer.WriteLine(s);
|
this.writer.WriteLine(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes this sink, freeing all of the resources it uses.
|
/// Disposes this sink, freeing all of the resources it uses.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
|
lock (this.file) {
|
||||||
if (!this.reopenOnWrite)
|
if (!this.reopenOnWrite)
|
||||||
this.writer.Dispose();
|
this.writer.Dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,13 +12,19 @@ namespace ExtremelySimpleLogger {
|
||||||
/// The string that this sink currently contains.
|
/// The string that this sink currently contains.
|
||||||
/// Can be cleared using <see cref="Clear"/>.
|
/// Can be cleared using <see cref="Clear"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Value => this.builder.ToString();
|
public string Value {
|
||||||
|
get {
|
||||||
|
lock (this.builder)
|
||||||
|
return this.builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs the given message, which has already been formatted using <see cref="Sink.Formatter"/>.
|
/// Logs the given message, which has already been formatted using <see cref="Sink.Formatter"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="s">The message to log</param>
|
/// <param name="s">The message to log</param>
|
||||||
public override void Log(string s) {
|
public override void Log(string s) {
|
||||||
|
lock (this.builder)
|
||||||
this.builder.AppendLine(s);
|
this.builder.AppendLine(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +33,7 @@ namespace ExtremelySimpleLogger {
|
||||||
/// After this call, <see cref="Value"/> will be empty.
|
/// After this call, <see cref="Value"/> will be empty.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Clear() {
|
public void Clear() {
|
||||||
|
lock (this.builder)
|
||||||
this.builder.Clear();
|
this.builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue