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


C# Log.ToString方法代码示例

本文整理汇总了C#中Log.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Log.ToString方法的具体用法?C# Log.ToString怎么用?C# Log.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Log的用法示例。


在下文中一共展示了Log.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Log

        /// <summary>
        /// Log a message.
        /// </summary>
        /// <param name="message">Message to log. </param>
        /// <param name="level">Error severity level. </param>
        public void Log(Log.Level level, string message)
        {
            FileStream fileStream = null;
            StreamWriter writer = null;
            StringBuilder messageBuilder = new StringBuilder();

            try
            {
                fileStream = _logFile.Open(FileMode.OpenOrCreate,
                          FileAccess.Write, FileShare.Read);
                writer = new StreamWriter(fileStream);

                // Set the file pointer to the end of the file
                writer.BaseStream.Seek(0, SeekOrigin.End);

                // Create the message
                messageBuilder.Append(System.DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"))
                   .Append(" | ").Append(level.ToString()).Append(" | ").Append(message);

                // Force the write to the underlying file
                writer.WriteLine(messageBuilder.ToString());
                writer.Flush();
            }
            finally
            {
                if (writer != null) 
                    writer.Close();
            }
        }
开发者ID:EarlBoss,项目名称:picasastarter,代码行数:34,代码来源:FileLogger.cs

示例2: WriteMessage

        public override void WriteMessage(string message, Log.MessageType type)
        {
            string newLine = Environment.NewLine;

            FileStream fileStream = null;
            StreamWriter writer = null;
            StringBuilder mess = new StringBuilder();

            try
            {
                fileStream = new FileStream(_fileLocation + this.FileName, FileMode.OpenOrCreate, FileAccess.Write);
                writer = new StreamWriter(fileStream);

                lock (SyncObject)
                {
                    writer.BaseStream.Seek(0, SeekOrigin.End);

                    // [DateTime] [error/warn] [client 127.0.0.1] 200 (code) - "Url" - "Info system"

                    string banner = string.Format("[" + type.ToString().ToUpper() + "][" + DateTimeLog + "]");
                    string body = message;
                    string end = "----------------------------------------------------";

                    mess.AppendLine(banner + newLine + body + newLine + end);

                    writer.Write(mess);
                }
                writer.Flush();
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
开发者ID:DarkSideMoon,项目名称:HTTP-Server,代码行数:35,代码来源:ResponseLogger.cs

示例3: Write

        /// <summary>
        /// Log message.
        /// </summary>
        public void Write(Log.Level level, string format, params object[] args)
        {
            string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string message;

            if (args.Length > 0)
            {
                message = string.Format(format, args);
            }
            else
            {
                message = format;
            }
            Write(dt + ' ' + level.ToString() + ' ' + message);
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:18,代码来源:Console.cs

示例4: write

            void write(Log.MessageType type, string message, string details)
            {
                lock (this)
                {
                    if (Writing != null)
                        Writing.Invoke(type, message, details);

                    if (Log.write_log)
                    {
                        if (log_writer == null)
                            log_writer = new StreamWriter(Path, true);

                        details = string.IsNullOrWhiteSpace(details) ? "" : "\r\n\r\n" + details;

                        switch (type)
                        {
                            case Log.MessageType.INFORM: message = "INFORM: " + message; break;
                            case Log.MessageType.WARNING: message = "WARNING: " + message; break;
                            case Log.MessageType.ERROR:
                                message = "ERROR: " + message + details;
                                _ErrorCount++;
                                break;
                            case Log.MessageType.EXIT:
                                message = "EXIT: " + message + details;
                                _ErrorCount++;
                                break;
                            case Log.MessageType.TRACE: message = "TRACE: " + message; break;
                            case Log.MessageType.LOG: break;
                            default: throw new Exception("No case for " + type.ToString());
                        }

                        if (MaxFileSize > 0)
                        {
                            FileInfo fi = new FileInfo(Path);
                            if (fi.Length > MaxFileSize)
                            {
                                log_writer.Close();

                                int counter = 0;
                                file_name = Regex.Replace(file_name, @"(\d+_)(\d+)(\.[^\.]+)$",
                                    (Match m) =>
                                    {
                                        counter = int.Parse(m.Groups[2].Value) + 1;
                                        return m.Groups[1].Value + counter + m.Groups[3].Value;
                                    }
                                    );
                                if (counter < 1)
                                    file_name = Regex.Replace(file_name, @"\.[^\.]+$", @"_1$0");

                                log_writer = new StreamWriter(Path, true);
                            }
                        }
                        //if (!string.IsNullOrWhiteSpace(details))
                        //    message += "\r\n\r\n" + details;
                        log_writer.WriteLine(DateTime.Now.ToString("[dd-MM-yy HH:mm:ss] ") + message);
                        log_writer.Flush();
                    }
                }
            }
开发者ID:sergeystoyan,项目名称:CliverBot,代码行数:59,代码来源:Log.Writer.cs

示例5: SaveLog

 public void SaveLog(Log log)
 {
     this.Save(log.DateTime, log.ToString());
 }
开发者ID:bzamecnik,项目名称:XRouter,代码行数:4,代码来源:LoggerFileStorage.cs

示例6: TestTranslations

        public void TestTranslations()
        {
            Log log = new Log(() => Resources.TestString, "p0").Add();

            var culture = Resources.Culture;

            Resources.Culture = Translation.DefaultCulture;
            Trace.WriteLine(log.ToString(Log.VerboseFormat) + Environment.NewLine);
            Assert.AreEqual(string.Format(Resources.TestString, "p0"), log.Message);

            Resources.Culture = CultureInfo.InvariantCulture;
            Trace.WriteLine(log.ToString(Log.VerboseFormat, Resources.Culture) + Environment.NewLine);
            Assert.AreEqual(string.Format(Resources.TestString, "p0"), log.GetMessage(Resources.Culture));

            Resources.Culture = CultureHelper.GetCultureInfo("fr-FR");
            Trace.WriteLine(log.ToString(Log.VerboseFormat, Resources.Culture) + Environment.NewLine);
            Assert.AreEqual(string.Format(Resources.TestString, "p0"), log.GetMessage(Resources.Culture));

            Resources.Culture = CultureHelper.GetCultureInfo("de-DE");
            Trace.WriteLine(log.ToString(Log.VerboseFormat, Resources.Culture) + Environment.NewLine);
            Assert.AreEqual(string.Format(Resources.TestString, "p0"), log.GetMessage(Resources.Culture));

            Resources.Culture = culture;
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:24,代码来源:LoggingTest.cs

示例7: TestToFromDictionary

        public void TestToFromDictionary()
        {
            Log initialLog = new Log(_logDictionary);
            Trace.WriteLine(initialLog.ToString(Log.AllFormat));
            Trace.WriteLine(string.Empty);

            Dictionary<string, string> resultDictionary = initialLog.AllProperties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            Log resultLog = new Log(initialLog.AllProperties);
            Trace.WriteLine(resultLog.ToString(Log.AllFormat));
            Trace.WriteLine(string.Empty);

            Log.Flush().Wait();
            CollectionAssert.AreEquivalent(_logDictionary, resultDictionary);
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:15,代码来源:LoggingTest.cs


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