forked from andrewdavey/cassette
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture trace output during start-up and display in HUD page
- Loading branch information
1 parent
59e01d9
commit ea21684
Showing
5 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Cassette.Web | ||
{ | ||
class StringBuilderTraceListener : TraceListener | ||
{ | ||
readonly StringBuilder builder = new StringBuilder(); | ||
|
||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) | ||
{ | ||
if (eventType == TraceEventType.Information) | ||
{ | ||
WriteLine(eventCache.DateTime.TimeOfDay + " - " + message); | ||
} | ||
else | ||
{ | ||
base.TraceEvent(eventCache, source, eventType, id, message); | ||
} | ||
} | ||
|
||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args) | ||
{ | ||
var message = args == null ? format : string.Format(format, args); | ||
if (eventType == TraceEventType.Information) | ||
{ | ||
WriteLine(eventCache.DateTime.TimeOfDay + " - " + message); | ||
} | ||
else | ||
{ | ||
base.TraceEvent(eventCache, source, eventType, id, message); | ||
} | ||
} | ||
|
||
public override void Write(string message) | ||
{ | ||
builder.Append(message); | ||
} | ||
|
||
public override void WriteLine(string message) | ||
{ | ||
builder.AppendLine(message); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return builder.ToString(); | ||
} | ||
} | ||
} |