本文整理汇总了C#中LogSource.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogSource.ToString方法的具体用法?C# LogSource.ToString怎么用?C# LogSource.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogSource
的用法示例。
在下文中一共展示了LogSource.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
internal static void Write(LogSource Source, Exception Ex)
{
if (Ex == null || !EnableLogging) return;
if (Ex.InnerException != null) Ex = Ex.InnerException;
try
{
if (!Directory.Exists(ApplicationSettings.DataPath + "log\\"))
Directory.CreateDirectory(ApplicationSettings.DataPath + "log\\");
LogFilePath = ApplicationSettings.DataPath + "log\\LOG." + DateTime.Today.ToString("yyyy-MM-dd") + ".EXCEPTION";
LogStream = new FileStream(LogFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
Log = new StreamWriter(LogStream, Encoding.UTF8);
StringBuilder SB = new StringBuilder();
if (LogStream.Length < 21)
SB.AppendLine("<ERRORLOG>");
else
LogStream.Position = LogStream.Length - 13;
SB.AppendLine(" <LOG TIME=\"{0}\" SOURCE=\"{1}\">");
SB.AppendLine(" <EXCEPTION>{2}</EXCEPTION>");
SB.AppendLine(" <MESSAGE>{3}</MESSAGE>");
SB.AppendLine(" <SOURCE>{4}</SOURCE>");
SB.AppendLine(" <STACK>{5}</STACK>");
SB.AppendLine(" <TARGETSITE>{6}</TARGETSITE>");
SB.AppendLine(" </LOG>");
SB.AppendLine("</ERRORLOG>"); // End the xml file
Log.Write(
string.Format(SB.ToString(),
DateTime.Now.ToString("HH:mm:ss"),
Source.ToString(),
Ex.ToString(),
Ex.Message,
Ex.Source,
Ex.StackTrace,
Ex.TargetSite.Name));
SB = null;
}
catch (Exception Exn)
{ }
finally
{
if (Log != null) Log.Close(); Log = null;
if (LogStream != null) LogStream.Close(); LogStream = null;
}
}
示例2: writeMessage
private void writeMessage(StreamWriter sw, LogType type, LogSource src, string message, Exception ex, bool writeToConsole)
{
string line = getTimeString() + " : " + type.ToString() + " : " + src.ToString() + " : " + message;
if (ex != null)
line += ", EXCEPTION: " + ex.ToString();
sw.WriteLine(line);
sw.Flush();
if (writeToConsole)
{
switch (type)
{
case (LogType.Error):
Console.ForegroundColor = ConsoleColor.Red;
break;
case (LogType.Warning):
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case (LogType.Progress):
break;
default:
throw new NotImplementedException("Type " + type + " is not handled");
}
Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
示例3: LogError
static public void LogError(LogSource source, string message)
{
EventLog eventLog = new EventLog();
eventLog.Source = source.ToString();
eventLog.WriteEntry(message, EventLogEntryType.Error);
}
示例4: LogInformation
static public void LogInformation(LogSource source, string message)
{
EventLog eventLog = new EventLog();
eventLog.Source = source.ToString();
eventLog.WriteEntry(message, EventLogEntryType.Information);
}
示例5: Warn
/// <summary>
/// Logs the specified message with a debug severity.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="source">The source.</param>
/// <param name="args">The args.</param>
public void Warn(string message, LogSource source, params object[] args)
{
ILog log = LogManager.GetLogger(source.ToString());
log.WarnFormat(message, args);
}
示例6: Write
public static void Write(string strMessage, LogSource Source, LogLevel Level, DateTime LogDate, int intServerID)
{
Console.WriteLine(strMessage);
_YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter ta = new _YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter();
ta.Insert(LogDate, Source.ToString(), strMessage, (int)Level, intServerID);
}