本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例5: Write
public void Write(LogEntry entry)
{
if (Enabled)
{
FileStreamWriter.Write(Serializer.Serialize(entry));
}
}
示例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)
};
}
示例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);
}
示例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);
}
}
示例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));
}
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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());
}
示例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();
}
}