本文整理汇总了C#中LogEntry.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntry.ToString方法的具体用法?C# LogEntry.ToString怎么用?C# LogEntry.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntry
的用法示例。
在下文中一共展示了LogEntry.ToString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
void ILoggingListener.Write(LogEntry entry)
{
if (_isDebug)
{
System.Diagnostics.Debug.WriteLine(entry.ToString());
}
else
{
System.Diagnostics.Trace.WriteLine(entry.ToString());
}
}
示例2: Write
public void Write(LogEntry entry)
{
string filename = GetPath();
string path = Path.GetDirectoryName(filename);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (StreamWriter writer = new StreamWriter(filename, true, Encoding.Unicode))
writer.Write(entry.ToString());
}
示例3: LogEntryToStringTest
public void LogEntryToStringTest()
{
//Arrange
var time = new StubITimeProvider {TimeGet = () => new DateTime(2000, 01, 02, 13, 1, 40, 100)};
var entry = new LogEntry(time) {Source = "UnitTest", Message = "Sample log entry"};
//Assert
var result = entry.ToString();
//Act
Assert.AreEqual("2000-01-02-01:01:40:100|UnitTest |Sample log entry", result);
}
示例4: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StringWriter writer = new StringWriter();
FormattedEventLogTraceListener listener = new FormattedEventLogTraceListener(CommonUtil.EventLogSourceName, CommonUtil.EventLogNameCustom, null);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 1, testEntry);
Assert.AreEqual(testEntry.ToString(), CommonUtil.GetLastEventLogEntryCustom());
}
示例5: AddLogEntry
internal void AddLogEntry(LogEntry logEntry) {
if (_logEntries.Count >= MaxLogEntries)
return;
lock (_logEntries)
_logEntries.Add(logEntry);
if (!ShouldWriteToTestOutput)
return;
try {
_testOutputHelper.WriteLine(logEntry.ToString(false));
} catch (Exception) { }
}
示例6: FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StringWriter writer = new StringWriter();
FormattedTextWriterTraceListener listener = new FormattedTextWriterTraceListener(writer);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, testEntry);
string writtenData = writer.ToString();
string testEntryToString = testEntry.ToString();
Assert.IsTrue(-1 != writtenData.IndexOf(testEntryToString));
}
示例7: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testLogEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StreamWriter writer = new StreamWriter("trace.log");
FlatFileTraceListener listener = new FlatFileTraceListener(writer);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
source.TraceData(TraceEventType.Error, 0, testLogEntry);
listener.Dispose();
string strFileContents = GetFileContents("trace.log");
string testLogEntryAsString = testLogEntry.ToString();
Assert.IsTrue(-1 != strFileContents.IndexOf(testLogEntryAsString));
}
示例8: Convert
private LogEventInfo Convert(LogEntry entry)
{
var logEventInfo = new LogEventInfo {Message = entry.ToString()};
switch (entry.Level)
{
case LogLevel.Trace:
logEventInfo.Level = NLog.LogLevel.Trace;
break;
case LogLevel.Debug:
logEventInfo.Level = NLog.LogLevel.Debug;
break;
case LogLevel.Info:
logEventInfo.Level = NLog.LogLevel.Info;
break;
case LogLevel.Warn:
logEventInfo.Level = NLog.LogLevel.Warn;
break;
case LogLevel.Error:
logEventInfo.Level = NLog.LogLevel.Error;
break;
case LogLevel.Fatal:
logEventInfo.Level = NLog.LogLevel.Fatal;
break;
default:
throw new ArgumentOutOfRangeException();
}
if (entry.Exception != null)
{
logEventInfo.Exception = entry.Exception;
}
if (entry.EventId.HasValue)
{
logEventInfo.Properties["eventID"] = entry.EventId.Value;
}
logEventInfo.TimeStamp = DateTime.UtcNow;
return logEventInfo;
}
示例9: AddEntry
/// <summary>adds an entry to the log</summary>
/// <param name="entry">entry to add</param>
public void AddEntry(LogEntry entry)
{
if (!_Listening)
return;
try
{
if (IsLoggingAsText)
{
TextLogWriter.WriteLine(entry.ToString());
TextLogWriter.Flush();
}
if (IsLoggingAsHTML)
{
string color;
switch (entry.EntryType)
{
case LogEntryType.VERBOSE: color = "gray"; break;
case LogEntryType.SUCCESS: color = "green"; _NumPasses++; break;
case LogEntryType.FAILURE: color = "red"; _NumFailures++; break;
case LogEntryType.ERROR:
case LogEntryType.C_ERROR: color = "red"; _NumErrors++; break;
case LogEntryType.WARNING: color = "orange"; _NumWarnings++; break;
case LogEntryType.COMMENT: color = "blue"; break;
default: color = "black"; break;
}
// write the entry's remark
StringBuilder sb = new StringBuilder();
sb.Append("<span style=\"color:");
sb.Append(color);
sb.Append("; white-space:pre\">");
sb.Append(entry.ToString());
sb.Append("</span><br />\n");
HTMLLogWriter.Write(sb.ToString());
HTMLLogWriter.Flush();
}
}
catch { Close(); }
}
示例10: TestToString2
public void TestToString2()
{
var row = new LogEntry(new object[]{42});
row.ToString().Should().Be("42");
}
示例11: TestToString1
public void TestToString1()
{
var row = new LogEntry();
new Action(() => row.ToString()).ShouldNotThrow();
}
示例12: Keys_and_values_added_using_AddInfo_appear_in_formatted_output
public void Keys_and_values_added_using_AddInfo_appear_in_formatted_output()
{
var logEntry = new LogEntry("hello");
var guid = Guid.NewGuid();
logEntry.AddInfo("some_guid", guid);
Console.WriteLine(logEntry.ToString());
Assert.That(
logEntry.ToString(),
Is.StringContaining("some_guid"));
Assert.That(
logEntry.ToString(),
Is.StringContaining(guid.ToString()));
}
示例13: Subject_does_not_apear_in_params
public void Subject_does_not_apear_in_params()
{
var entry = new LogEntry<int>(123);
Assert.That(
entry.ToString().Split(new[] { "123" }, StringSplitOptions.None).Length,
Is.EqualTo(2));
}
示例14: GetLogEntryToString
public string GetLogEntryToString()
{
var ignored = TextFormatter.DefaultTextFormat;
LogEntry entry = new LogEntry { Message = "asdfg" };
return entry.ToString();
}