Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TextWriterLogListener.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.IO;
4 
5 namespace SiliconStudio.Core.Diagnostics
6 {
7  /// <summary>
8  /// A <see cref="LogListener"/> implementation redirecting its output to a <see cref="TextWriter"/>.
9  /// </summary>
11  {
12  /// <summary>
13  /// Initializes a new instance of the <see cref="TextWriterLogListener"/> class.
14  /// </summary>
15  /// <param name="logStream">The log stream.</param>
16  public TextWriterLogListener(Stream logStream)
17  {
18  LogWriter = new StreamWriter(logStream);
19  }
20 
21  /// <summary>
22  /// Initializes a new instance of the <see cref="TextWriterLogListener"/> class.
23  /// </summary>
24  /// <param name="logWriter">The log writer.</param>
26  {
27  LogWriter = logWriter;
28  }
29 
30  /// <summary>
31  /// Gets the log writer.
32  /// </summary>
33  /// <value>The log writer.</value>
34  public TextWriter LogWriter { get; private set; }
35 
36  protected override void OnLog(ILogMessage logMessage)
37  {
38  lock (LogWriter)
39  {
40  LogWriter.WriteLine(GetDefaultText(logMessage));
41  var exceptionMsg = GetExceptionText(logMessage);
42  if (!string.IsNullOrEmpty(exceptionMsg))
43  {
44  LogWriter.WriteLine(exceptionMsg);
45  }
46  }
47  }
48 
49  protected override void Flush()
50  {
51  if (UseFlushAsync)
52  {
53  LogWriter.FlushAsync();
54  }
55  else
56  {
57  LogWriter.Flush();
58  }
59  }
60  }
61 }
A LogListener implementation redirecting its output to a TextWriter.
override void OnLog(ILogMessage logMessage)
Called when a log occurred.
override void Flush()
Flush the log, method to be implemented in a subclass.
A base class to implement a log listener
Definition: LogListener.cs:10
The base interface for log messages used by the logging infrastructure.
Definition: ILogMessage.cs:8
TextWriterLogListener(TextWriter logWriter)
Initializes a new instance of the TextWriterLogListener class.
TextWriterLogListener(Stream logStream)
Initializes a new instance of the TextWriterLogListener class.