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


C# LogEntry.ToString方法代码示例

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


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

示例1:

 void ILoggingListener.Write(LogEntry entry)
 {
     if (_isDebug)
     {
         System.Diagnostics.Debug.WriteLine(entry.ToString());
     }
     else
     {
         System.Diagnostics.Trace.WriteLine(entry.ToString());
     }
 }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:11,代码来源:DiagnosticsLoggingListener.cs

示例2: Write

        public void Write(LogEntry entry)
        {
            string filename = GetPath();
            string path = Path.GetDirectoryName(filename);

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            using (StreamWriter writer = new StreamWriter(filename, true, Encoding.Unicode))
                writer.Write(entry.ToString());
        }
开发者ID:Genbox,项目名称:Log.NET,代码行数:11,代码来源:FlatFile.cs

示例3: LogEntryToStringTest

        public void LogEntryToStringTest()
        {
            //Arrange 
            var time = new StubITimeProvider {TimeGet = () => new DateTime(2000, 01, 02, 13, 1, 40, 100)};
            var entry = new LogEntry(time) {Source = "UnitTest", Message = "Sample log entry"};

            //Assert
            var result = entry.ToString();

            //Act
            Assert.AreEqual("2000-01-02-01:01:40:100|UnitTest            |Sample log entry", result);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:12,代码来源:LogEntryTest.cs

示例4: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists

        public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
        {
            LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            StringWriter writer = new StringWriter();
            FormattedEventLogTraceListener listener = new FormattedEventLogTraceListener(CommonUtil.EventLogSourceName, CommonUtil.EventLogNameCustom, null);

            // need to go through the source to get a TraceEventCache
            LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
            source.TraceData(TraceEventType.Error, 1, testEntry);

            Assert.AreEqual(testEntry.ToString(), CommonUtil.GetLastEventLogEntryCustom());
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:12,代码来源:FormattedEventLogListenerFixture.cs

示例5: AddLogEntry

        internal void AddLogEntry(LogEntry logEntry) {
            if (_logEntries.Count >= MaxLogEntries)
                return;

            lock (_logEntries)
                _logEntries.Add(logEntry);

            if (!ShouldWriteToTestOutput)
                return;

            try {
                _testOutputHelper.WriteLine(logEntry.ToString(false));
            } catch (Exception) { }
        }
开发者ID:geffzhang,项目名称:Foundatio,代码行数:14,代码来源:TestLoggerFactory.cs

示例6: FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists

        public void FormattedListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
        {
            LogEntry testEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            StringWriter writer = new StringWriter();
            FormattedTextWriterTraceListener listener = new FormattedTextWriterTraceListener(writer);

            // need to go through the source to get a TraceEventCache
            LogSource source = new LogSource("notfromconfig", SourceLevels.All);
            source.Listeners.Add(listener);
            source.TraceData(TraceEventType.Error, 0, testEntry);

            string writtenData = writer.ToString();
            string testEntryToString = testEntry.ToString();

            Assert.IsTrue(-1 != writtenData.IndexOf(testEntryToString));
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:16,代码来源:FormattedTextWriterListenerFixture.cs

示例7: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists

        public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
        {
            LogEntry testLogEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            StreamWriter writer = new StreamWriter("trace.log");
            FlatFileTraceListener listener = new FlatFileTraceListener(writer);

            // need to go through the source to get a TraceEventCache
            LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All);
            source.TraceData(TraceEventType.Error, 0, testLogEntry);
            listener.Dispose();

            string strFileContents = GetFileContents("trace.log");

            string testLogEntryAsString = testLogEntry.ToString();

            Assert.IsTrue(-1 != strFileContents.IndexOf(testLogEntryAsString));
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:17,代码来源:FlatFileTraceListenerFixture.cs

示例8: Convert

        private LogEventInfo Convert(LogEntry entry)
        {
            var logEventInfo = new LogEventInfo {Message = entry.ToString()};
            switch (entry.Level)
            {
                case LogLevel.Trace:
                    logEventInfo.Level = NLog.LogLevel.Trace;
                    break;
                case LogLevel.Debug:
                    logEventInfo.Level = NLog.LogLevel.Debug;
                    break;
                case LogLevel.Info:
                    logEventInfo.Level = NLog.LogLevel.Info;
                    break;
                case LogLevel.Warn:
                    logEventInfo.Level = NLog.LogLevel.Warn;
                    break;
                case LogLevel.Error:
                    logEventInfo.Level = NLog.LogLevel.Error;
                    break;
                case LogLevel.Fatal:
                    logEventInfo.Level = NLog.LogLevel.Fatal;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            if (entry.Exception != null)
            {
                logEventInfo.Exception = entry.Exception;
            }
            if (entry.EventId.HasValue)
            {
                logEventInfo.Properties["eventID"] = entry.EventId.Value;
            }
            logEventInfo.TimeStamp = DateTime.UtcNow;

            return logEventInfo;
        }
开发者ID:Hoejsgaard,项目名称:Hsc.Core,代码行数:38,代码来源:NLogLogger.cs

示例9: AddEntry

            /// <summary>adds an entry to the log</summary>
            /// <param name="entry">entry to add</param>
            public void AddEntry(LogEntry entry)
            {
                if (!_Listening)
                    return;
                try
                {
                    if (IsLoggingAsText)
                    {
                        TextLogWriter.WriteLine(entry.ToString());
                        TextLogWriter.Flush();
                    }

                    if (IsLoggingAsHTML)
                    {
                        string color;
                        switch (entry.EntryType)
                        {
                            case LogEntryType.VERBOSE: color = "gray"; break;
                            case LogEntryType.SUCCESS: color = "green"; _NumPasses++; break;
                            case LogEntryType.FAILURE: color = "red"; _NumFailures++; break;
                            case LogEntryType.ERROR:
                            case LogEntryType.C_ERROR: color = "red"; _NumErrors++; break;
                            case LogEntryType.WARNING: color = "orange"; _NumWarnings++; break;
                            case LogEntryType.COMMENT: color = "blue"; break;
                            default: color = "black"; break;
                        }

                        // write the entry's remark
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<span style=\"color:");
                        sb.Append(color);
                        sb.Append("; white-space:pre\">");
                        sb.Append(entry.ToString());
                        sb.Append("</span><br />\n");
                        HTMLLogWriter.Write(sb.ToString());
                        HTMLLogWriter.Flush();
                    }
                }
                catch { Close(); }
            }
开发者ID:jamesoram,项目名称:ios-auto,代码行数:42,代码来源:LogEngine.cs

示例10: TestToString2

 public void TestToString2()
 {
     var row = new LogEntry(new object[]{42});
     row.ToString().Should().Be("42");
 }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:5,代码来源:LogEntryTest.cs

示例11: TestToString1

 public void TestToString1()
 {
     var row = new LogEntry();
     new Action(() => row.ToString()).ShouldNotThrow();
 }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:5,代码来源:LogEntryTest.cs

示例12: Keys_and_values_added_using_AddInfo_appear_in_formatted_output

        public void Keys_and_values_added_using_AddInfo_appear_in_formatted_output()
        {
            var logEntry = new LogEntry("hello");
            var guid = Guid.NewGuid();
            logEntry.AddInfo("some_guid", guid);

            Console.WriteLine(logEntry.ToString());

            Assert.That(
                logEntry.ToString(),
                Is.StringContaining("some_guid"));

            Assert.That(
                logEntry.ToString(),
                Is.StringContaining(guid.ToString()));
        }
开发者ID:wli3,项目名称:Its.Log,代码行数:16,代码来源:LogEntryTests.cs

示例13: Subject_does_not_apear_in_params

        public void Subject_does_not_apear_in_params()
        {
            var entry = new LogEntry<int>(123);

            Assert.That(
                entry.ToString().Split(new[] { "123" }, StringSplitOptions.None).Length, 
                Is.EqualTo(2));
        }
开发者ID:wli3,项目名称:Its.Log,代码行数:8,代码来源:LogEntryTests.cs

示例14: GetLogEntryToString

        public string GetLogEntryToString()
        {
            var ignored = TextFormatter.DefaultTextFormat;
            LogEntry entry = new LogEntry { Message = "asdfg" };

            return entry.ToString();
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:7,代码来源:LogEntryFixture.cs


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