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


C# LogEntry.GetLoggerInfo方法代码示例

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


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

示例1: Enqueue

        /// <summary>
        /// Enqueue to be written
        /// </summary>
        /// <param name="entry"></param>
        /// <remarks>
        /// The entry might be written directly in the same thread or enqueued to be written
        /// later. It's up to each implementation to decide. Keep in mind that a logger should not
        /// introduce delays in the thread execution. If it's possible that it will delay the thread,
        /// enqueue entries instead and write them in a seperate thread.
        /// </remarks>
        public void Enqueue(LogEntry entry)
        {
            var method = entry.GetLoggerInfo();

            var tmp = String.Format("{0} {1} {2} {3} {4}",
                                    entry.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                                    entry.ThreadId.ToString().PadLeft(3),
                                    entry.UserName.PadRight(25),
                                    method.PadRight(40),
                                    entry.Message.Replace("\r\n", "\r\n\t"));

            Console.ForegroundColor = GetColor(entry);
            Console.WriteLine(tmp);
            if (entry.Exception != null)
            {
                var exception = entry.Exception;
                var tabs = "\t";
                while (exception != null)
                {
                    Console.WriteLine(tabs + entry.Exception.ToString().Replace("\r\n", "\r\n" + tabs));

                    exception = exception.InnerException;
                    tabs += "\t";
                }
            }
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:jmptrader,项目名称:Griffin.Logging,代码行数:37,代码来源:ConsoleTarget.cs

示例2: SaveEntry

        private void SaveEntry(LogEntry entry)
        {
            if (entry == null) throw new ArgumentNullException("entry");


            using (var connection = _providerFactory.CreateConnection())
            {
                Debug.Assert(connection != null, "connection != null");

                connection.ConnectionString = _configurationString.ConnectionString;
                connection.Open();

                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = InsertStatement;
                    cmd.AddParameter("userName", entry.UserName);
                    cmd.AddParameter("createdAt", entry.CreatedAt);

                    var value = entry.GetLoggerInfo();
                    cmd.AddParameter("source", value);
                    cmd.AddParameter("message", entry.Message);
                    cmd.AddParameter("exception", entry.Exception);
                    cmd.AddParameter("threadId", entry.ThreadId);
                    cmd.AddParameter("logLevel", (int) entry.LogLevel);
                    cmd.ExecuteNonQuery();
                }
            }
        }
开发者ID:jmptrader,项目名称:Griffin.Logging,代码行数:28,代码来源:AdoNetTarget.cs


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