本文整理汇总了C#中LogEntryType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntryType.ToString方法的具体用法?C# LogEntryType.ToString怎么用?C# LogEntryType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntryType
的用法示例。
在下文中一共展示了LogEntryType.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogMessageToTextFile
private static int LogMessageToTextFile(LogEntryType type, string message)
{
try
{
string logmsg = "----------------------------\r\n" + //separator for new log
"Local time: " + DateTime.Now.ToString() + "\r\n" + //local time
//summary info
"Application Name: " + applicationName + "\r\n" +
"Log Type: " + type.ToString() + "\r\n" +
"Error Message:\r\n" + message + "\r\n";
//allow error log to be encoded by local time
string logFileName = string.Format(errorLogFileName, DateTime.Now);
using (StreamWriter w = File.AppendText(logFileName))
{
w.Write(logmsg);
}
return 0; //logged to local file
}
catch (Exception e)
{
//ignore errors, avoid infinite loop of trying to log errors
#if DEBUG
System.Console.WriteLine(e.ToString());
System.Diagnostics.Debug.WriteLine(e.ToString());
#endif
return -1;
}
}
示例2: Custom
public void Custom(LogEntryType type, string message, Exception exception = null)
{
lock (writeLock)
{
writer.WriteLine("{0}: {1}", type.ToString().ToUpper(), message);
WriteException(exception);
}
}
示例3: WriteToTraceLevel
/* Handler designed to use the appropriate tracing tool depending upon the intent of the end-user */
private static void WriteToTraceLevel(string message, LogEntryType entryType)
{
switch(entryType)
{
case LogEntryType.Error: //Designed to fall-through to the failure case
case LogEntryType.Failure:
Trace.TraceError(message);
break;
case LogEntryType.Information:
Trace.TraceInformation(message);
break;
case LogEntryType.Warning:
Trace.TraceWarning(message);
break;
default:
Trace.WriteLine(message, entryType.ToString());
break;
}
}