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


C# LogEntry类代码示例

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


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

示例1: WhenLogging_ThenLogWriterWritesToTheInjectedStack

        public void WhenLogging_ThenLogWriterWritesToTheInjectedStack()
        {
            var logEntry = new LogEntry() { Message = "message" };
            this.logWriter.Write(logEntry);

            Assert.AreSame(logEntry, this.traceListener.tracedData);
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:7,代码来源:LogWriterInjectionFixture.cs

示例2: if

 void ILogOutput.Write(LogEntry entry)
 {
     if (entry.Type == LogMessageType.Error)
         this.lastErrorMessage = entry.Message;
     else if (entry.Type == LogMessageType.Warning)
         this.lastWarningMessage = entry.Message;
 }
开发者ID:SirePi,项目名称:duality,代码行数:7,代码来源:TestingLogOutput.cs

示例3: Write

        public override void Write(LogEntry entry)
        {
            string caller;
            if (UseStackFrame)
            {
                var frame = GetStackFrame();
                caller = frame.GetMethod().ReflectedType.Name + "." +
                             frame.GetMethod().Name + "():" + frame.GetFileLineNumber();
            }
            else
            {
                caller = LoggedType.Namespace ?? "";
            }

            var color = Console.ForegroundColor;
            Console.ForegroundColor = GetColor(entry.LogLevel);
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + caller.PadRight(50) +
                              entry.LogLevel.ToString().PadRight(10) + entry.Message);

            if (entry.Exception != null)
            {
                var sb = new StringBuilder();
                BuildExceptionDetails(entry.Exception, 4, sb);
                Console.WriteLine(sb.ToString());
            }


            Console.ForegroundColor = color;
        }
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:29,代码来源:ConsoleLogger.cs

示例4: LogEntry_InnerException_DetailsFromInnerException

 public void LogEntry_InnerException_DetailsFromInnerException()
 {
     const string InnerExceptionMessage = "() Inner exception message.";
     const string OuterExceptionMessage = ")( Outer exception message.";
     try
     {
         try
         {
             throw new Exception(InnerExceptionMessage);
         }
         catch (Exception innerException)
         {
             throw new Exception(OuterExceptionMessage, innerException);
         }
     }
     catch (Exception outerException)
     {
         var logEntry = new LogEntry(
             LogType.Error,
             "test",
             outerException,
             null);
         Assert.AreEqual(InnerExceptionMessage, logEntry.ExceptionMessage);
     }
 }
开发者ID:uncas,项目名称:core,代码行数:25,代码来源:LogEntryTests.cs

示例5: Write

 public void Write(LogEntry entry)
 {
     if (Enabled)
     {
         FileStreamWriter.Write(Serializer.Serialize(entry));
     }
 }
开发者ID:rtaylornc,项目名称:IntelliMediaCore,代码行数:7,代码来源:FileLogger.cs

示例6: MessageMarkup

    public object[] MessageMarkup(LogEntry logEntry, int index)
    {
        if (!logEntry.Message.Contains("\n"))
        {
            string encodedMessage = EncodeXml10InvalidCharacters(logEntry.Message);
            return new object[] { encodedMessage };
        }

        string[] lines = EncodeXml10InvalidCharacters(logEntry.Message).Trim().Split('\n');

        if (lines.Length < 7)
        {
            return new object[]
            {
                new XElement("pre", EncodeXml10InvalidCharacters(logEntry.Message.Replace("\n", "")))
            };
        }

        return new object[]
        {
            PreTag(lines, 0, 2),
            new XElement("a",
                new XAttribute("id", "a" + index),
                new XAttribute("href", "#"),
                new XAttribute("onclick", string.Format("document.getElementById('log{0}').style.display = 'block';document.getElementById('a{0}').style.display = 'none'", index)),
                new XAttribute("class", "expandCode"),
                ". . ."),
            PreTag(lines, 2, lines.Length - 4,
                new XAttribute("id", "log" + index),
                new XAttribute("style", "display:none;")),
            PreTag(lines, lines.Length - 2, 2)
        };
    }
开发者ID:RuneAndersen,项目名称:C1-CMS,代码行数:33,代码来源:log.aspx.cs

示例7: LogEntrySerialiseDeserialise

        public void LogEntrySerialiseDeserialise()
        {
            var originalLogEntry = new LogEntry()
            {
                Timestamp = DateTime.UtcNow,
                Status = LogStatus.Fatal,
                GroupKey = Guid.NewGuid(),
                TargetKey = Guid.NewGuid(),
                InstanceKey = Guid.NewGuid(),
                LogContent = "Test Log Entry",
            };

            LogEntry secondLogEntry;
            using (var stream = originalLogEntry.Serialise())
            {
                secondLogEntry = new LogEntry(stream);
            }

            Assert.AreEqual(originalLogEntry.Timestamp, secondLogEntry.Timestamp);
            Assert.AreEqual(originalLogEntry.Status, secondLogEntry.Status);
            Assert.AreEqual(originalLogEntry.GroupKey, secondLogEntry.GroupKey);
            Assert.AreEqual(originalLogEntry.TargetKey, secondLogEntry.TargetKey);
            Assert.AreEqual(originalLogEntry.InstanceKey, secondLogEntry.InstanceKey);
            Assert.AreEqual(originalLogEntry.LogContent, secondLogEntry.LogContent);
        }
开发者ID:danielrbradley,项目名称:Plywood,代码行数:25,代码来源:LogEntryTests.cs

示例8: CreateRandomLogEntries

	void CreateRandomLogEntries(int howMany)
	{
		for (int i = 0; i < howMany; i++)
		{
			float date = Random.Range(i* RTSDirector.instance.gameDay, ((i+1))*RTSDirector.instance.gameDay)/ howMany;

			LogEntry scratchLogEntry = new LogEntry();

			scratchLogEntry.date = date;
			//scratchLogEntry.location = whatever;
			scratchLogEntry.who = scratchLogEntry.whoArray[Random.Range(0, scratchLogEntry.whoArray.Length)] ;
			scratchLogEntry.didWhat = scratchLogEntry.didWhatArray[Random.Range(0, scratchLogEntry.didWhatArray.Length)];

			scratchLogEntry.whatSubject = scratchLogEntry.whatSubjectArray[Random.Range(0, scratchLogEntry.whatSubjectArray.Length)];
			if(scratchLogEntry.whatSubject == "floating debris")
				scratchLogEntry.doingWhat = "";
			else
				scratchLogEntry.doingWhat = scratchLogEntry.doingWhatArray[Random.Range(0, scratchLogEntry.doingWhatArray.Length)];

			scratchLogEntry.where = scratchLogEntry.whereArray[Random.Range(0, scratchLogEntry.whereArray.Length)];

			scratchLogEntry.message = "Day " + scratchLogEntry.date.ToString("n1") + ": "+
				scratchLogEntry.who+ " "+
				scratchLogEntry.didWhat + " "+ 
				scratchLogEntry.whatSubject	+ " "+
				scratchLogEntry.doingWhat + " "+
				scratchLogEntry.where + ".\n\n";

			logEntryList.Add(scratchLogEntry);
		}
	}
开发者ID:JtheSpaceC,项目名称:Space-Game,代码行数:31,代码来源:ActivityLog.cs

示例9: SendMessageCore

        /// <summary>
        /// Append the log entry to the configured text file.
        /// </summary>
        /// <param name="logEntry"><see cref="LogEntry"></see> to be appended to logging file</param>
        protected override void SendMessageCore(LogEntry logEntry)
        {
            if (ValidateParameters(logEntry))
            {
                try
                {
                   webservice.Logging ws = new webservice.Logging();
                   ws.Url = this.wsSinkData.Url;

                   webservice.WSLogEntry wsLogEntry = new webservice.WSLogEntry();
                   wsLogEntry.Message = logEntry.Message;
                   wsLogEntry.Priority = logEntry.Priority;
                   wsLogEntry.Category = logEntry.Category;
                   wsLogEntry.EventId = logEntry.EventId;
                   wsLogEntry.Severity = (webservice.Severity)Enum.Parse(typeof(webservice.Severity), logEntry.Severity.ToString());
                   wsLogEntry.Title = logEntry.Title;
                   wsLogEntry.ExtendedProperties = WSLogEntry.ToJaggedArray((Hashtable)logEntry.ExtendedProperties);

                   ws.Log(wsLogEntry);

                }
                catch (Exception e)
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
                    throw;
                }
                catch
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:36,代码来源:WSSink.cs

示例10: FormatToken

        /// <summary>
        /// Iterates through each entry in the dictionary and display the key and/or value.
        /// </summary>
        /// <param name="tokenTemplate">Template to repeat for each key/value pair.</param>
        /// <param name="log">Log entry containing the extended properties dictionary.</param>
        /// <returns>Repeated template for each key/value pair.</returns>
        public override string FormatToken(string tokenTemplate, LogEntry log)
        {
            StringBuilder dictionaryBuilder = new StringBuilder();
            foreach (KeyValuePair<string, object> entry in log.ExtendedProperties)
            {
                StringBuilder singlePair = new StringBuilder(tokenTemplate);
                string keyName = "";
                if (entry.Key != null)
                {
                    keyName = entry.Key.ToString();
                }
                singlePair.Replace(DictionaryKeyToken, keyName);

                string keyValue = "";
                if (entry.Value != null)
                {
                    keyValue = entry.Value.ToString();
                }
                singlePair.Replace(DictionaryValueToken, keyValue);

                dictionaryBuilder.Append(singlePair.ToString());
            }

            return dictionaryBuilder.ToString();
        }
开发者ID:wuyingyou,项目名称:uniframework,代码行数:31,代码来源:DictionaryToken.cs

示例11: LogWrite

        /// <summary>
        /// Writes trace input to <see cref="Log.Write" />.
        /// </summary>
        /// <remarks>This is the method into which all TraceListener Write methods call.</remarks>
        private static void LogWrite(object o, string category = null)
        {
            if (RecursionCounter.Depth > 0)
            {
                return;
            }
            using (RecursionCounter.Enter())
            {
                LogEntry logEntry;

                var d = o as Delegate;
                if (d != null)
                {
                    logEntry = new LogEntry(d.DynamicInvoke(), d.GetAnonymousMethodInfo());
                }
                else if (o is LogEntry)
                {
                    logEntry = (LogEntry) o;
                }
                else
                {
                    logEntry = new LogEntry(o);
                }

                logEntry.Category = category;
                Log.Write(logEntry);
            }
        }
开发者ID:wli3,项目名称:Its.Log,代码行数:32,代码来源:TraceListener.cs

示例12: GetColorByEntry

 protected ConsoleColor GetColorByEntry(LogEntry logEntry)
 {
     if(!this.UseColor)
         return Console.ForegroundColor;
     switch(logEntry.LogType) {
         case LogEntry.LogTypes.Debug:
             return ConsoleColor.DarkGray;
             break;
         case LogEntry.LogTypes.Error:
             return XConsole.XConsole.ErrorColor;
             break;
         case LogEntry.LogTypes.Exception:
                                 return XConsole.XConsole.ErrorColor;
             break;
         case LogEntry.LogTypes.Fatal:
                                 return XConsole.XConsole.ErrorColor;
             break;
         case LogEntry.LogTypes.Success:
             return XConsole.XConsole.SuccessColor;
             break;
         case LogEntry.LogTypes.Warn:
             return XConsole.XConsole.WarningColor;
             break;
     }
     return Console.ForegroundColor;
 }
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:26,代码来源:ConsoleLogger.cs

示例13: FormatLogEntry

        /// <summary>
        /// Format a log entry as it should be written to the file
        /// </summary>
        /// <param name="entry">Entry to format</param>
        /// <returns>
        /// Formatted entry
        /// </returns>
        protected override string FormatLogEntry(LogEntry entry)
        {
            string result;
            var ex = entry.Exception; // to satisfy code contracts
            if (ex != null)
            {
                result= string.Format("{0} {1} {2} {3} {4} {5}\r\n{6}\r\n",
                                     entry.CreatedAt.ToString(Configuration.DateTimeFormat),
                                     entry.LogLevel.ToString().PadRight(8, ' '),
                                     entry.ThreadId.ToString("000"),
                                     FormatUserName(entry.UserName, 16).PadRight(16),
                                     FormatStackTrace(entry.StackFrames, 40).PadRight(40),
                                     FormatMessage(entry.Message),
                                     FormatException(ex, 1)
                    );
            }
            else
            {
                result= string.Format("{0} {1} {2} {3} {4} {5}\r\n",
                              entry.CreatedAt.ToString(Configuration.DateTimeFormat),
                              entry.LogLevel.ToString().PadRight(8, ' '),
                              entry.ThreadId.ToString("000"),
                              FormatUserName(entry.UserName, 16).PadRight(16),
                              FormatStackTrace(entry.StackFrames, 40).PadRight(40),
                              FormatMessage(entry.Message)
                    );
            }

            // do make Code Contracts shut up.
            return string.IsNullOrEmpty(result) ? "Invalid entry" : result;
        }
开发者ID:jmptrader,项目名称:griffin,代码行数:38,代码来源:PaddedFileTarget.cs

示例14: ApplyResolvesClientIpAddress

        public void ApplyResolvesClientIpAddress()
        {
            var lookup = new Mock<IIpLookupService>();
            var target = new GeoLookupTransformation(lookup.Object);

            string cIpAddress = "myClientIp";

            string sIpAddress = "myServerIp";

            var entry = new LogEntry
            {
                cIp = cIpAddress,
                sIp = sIpAddress,
            };

            lookup.Setup(l => l.GetCountry(It.IsAny<string>())).Returns(new Country(TestCountryCode, TestCountryName));

            target.Apply(entry);

            Assert.Equal(TestCountryName, entry.CountryName);
            Assert.Equal(TestCountryCode, entry.CountryCode);

            lookup.Verify(l => l.GetCountry(sIpAddress), Times.Never());
            lookup.Verify(l => l.GetCountry(cIpAddress), Times.AtLeastOnce());
        }
开发者ID:peschuster,项目名称:LogImporter,代码行数:25,代码来源:GeoLookupTransformationTest.cs

示例15: SendLogEntry

        void SendLogEntry(WmiTraceListener listener,
                          LogEntry logEntry)
        {
            ManagementScope scope = new ManagementScope(@"\\." + wmiPath);
            scope.Options.EnablePrivileges = true;

            StringBuilder sb = new StringBuilder("SELECT * FROM ");
            sb.Append("LogEntryV20");
            string query = sb.ToString();
            EventQuery eq = new EventQuery(query);

            using (ManagementEventWatcher watcher = new ManagementEventWatcher(scope, eq))
            {
                watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
                watcher.Start();

                LogSource source = new LogSource("notfromconfig", SourceLevels.All);
                source.Listeners.Add(listener);
                source.TraceData(TraceEventType.Error, 1, logEntry);

                BlockUntilWMIEventArrives();

                watcher.Stop();
            }
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:25,代码来源:WMIListenerFixture.cs


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