当前位置: 首页>>代码示例>>C#>>正文


C# LogSource.ToString方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:solunar66,项目名称:AdPlayer,代码行数:52,代码来源:LogWriter.cs

示例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;
            }
        }
开发者ID:ago1024,项目名称:Calindor,代码行数:31,代码来源:ServerLogger.cs

示例3: LogError

		static public void LogError(LogSource source, string message)
		{
			EventLog eventLog = new EventLog();
			eventLog.Source = source.ToString();
			eventLog.WriteEntry(message, EventLogEntryType.Error);
		}
开发者ID:SwarmCorp,项目名称:Swarmops,代码行数:6,代码来源:Logging.cs

示例4: LogInformation

		static public void LogInformation(LogSource source, string message)
		{
			EventLog eventLog = new EventLog();
			eventLog.Source = source.ToString();
			eventLog.WriteEntry(message, EventLogEntryType.Information);
		}
开发者ID:SwarmCorp,项目名称:Swarmops,代码行数:6,代码来源:Logging.cs

示例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);
 }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:11,代码来源:Log4NetLogger.cs

示例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);
 }
开发者ID:richardbenson,项目名称:YAMS2,代码行数:6,代码来源:Log.cs


注:本文中的LogSource.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。