本文整理汇总了C#中log4net.Core.LoggingEvent类的典型用法代码示例。如果您正苦于以下问题:C# LoggingEvent类的具体用法?C# LoggingEvent怎么用?C# LoggingEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingEvent类属于log4net.Core命名空间,在下文中一共展示了LoggingEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WriteLog
public void WriteLog(ICorrelation correlation, LogEventLevel eventLevel, Exception exception, string formatMessage, params object[] args)
{
if (log == null)
{
log = loggerRepository.GetLogger(sourceType);
}
if (eventLevel == LogEventLevel.Verbose && !log.IsDebugEnabled)
{
return;
}
if (args != null && args.Length != 0)
{
formatMessage = string.Format(formatMessage, args);
}
log4net.Core.ILogger logger = log.Logger;
LoggingEvent logEvent = new LoggingEvent(sourceType, logger.Repository, logger.Name, MapEventLevel(eventLevel), formatMessage, exception);
if (correlation != null)
{
logEvent.Properties["CallerId"] = correlation.CallerId;
logEvent.Properties["CorrelationId"] = correlation.CorrelationId;
}
logger.Log(logEvent);
}
开发者ID:affecto,项目名称:dotnet-Logging,代码行数:29,代码来源:LogWriter.cs
示例2: Append
override protected void Append(LoggingEvent loggingEvent)
{
if (m_queue == null)
{
if (MessageQueue.Exists(m_queueName))
{
m_queue = new MessageQueue(m_queueName);
}
else
{
ErrorHandler.Error("Queue ["+m_queueName+"] not found");
}
}
if (m_queue != null)
{
Message message = new Message();
message.Label = RenderLabel(loggingEvent);
using(System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, new System.Text.UTF8Encoding(false, true));
base.RenderLoggingEvent(writer, loggingEvent);
writer.Flush();
stream.Position = 0;
message.BodyStream = stream;
m_queue.Send(message);
}
}
}
开发者ID:ittray,项目名称:LocalDemo,代码行数:32,代码来源:MsmqAppender.cs
示例3: Append
protected override void Append(LoggingEvent loggingEvent)
{
Level level = loggingEvent.Level;
string message = RenderLoggingEvent(loggingEvent);
if (level >= Level.Fatal)
{
Trace.Write(message, "Critical");
}
else if (level >= Level.Error)
{
Trace.TraceError(message);
}
else if (level >= Level.Warn)
{
Trace.TraceWarning(message);
}
else if (level >= Level.Info)
{
Trace.TraceInformation(message);
}
else
{
Trace.Write(message);
}
if (ImmediateFlush)
{
Trace.Flush();
}
}
开发者ID:johnbabb,项目名称:killrvideo-csharp,代码行数:31,代码来源:AzureTraceAppender.cs
示例4: SendBuffer
protected override void SendBuffer(LoggingEvent[] events)
{
BeginAsyncSend();
if (TryAsyncSend(events)) return;
EndAsyncSend();
HandleError("Failed to async send logging events in SendBuffer");
}
开发者ID:AaronLangley,项目名称:log4net.ElasticSearch,代码行数:7,代码来源:ElasticSearchAppender.cs
示例5: Append
protected override void Append(LoggingEvent le)
{
if (m_console != null)
m_console.LockOutput();
string loggingMessage = RenderLoggingEvent(le);
try
{
if (m_console != null)
{
m_console.Output(loggingMessage, le.Level);
}
else
{
if (!loggingMessage.EndsWith("\n"))
System.Console.WriteLine(loggingMessage);
else
System.Console.Write(loggingMessage);
}
}
catch (Exception e)
{
System.Console.WriteLine("Couldn't write out log message: {0}", e);
}
finally
{
if (m_console != null)
m_console.UnlockOutput();
}
}
开发者ID:savino1976,项目名称:Aurora-Sim,代码行数:30,代码来源:OpenSimAppender.cs
示例6: Convert
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
var text = GetFullyQualifiedName(loggingEvent);
if (m_precision == 0 || text == null || text.Length < 2)
{
writer.Write(text);
return;
}
var elements = text
.Trim()
.Trim(new[] { '.' })
.Split(new[] { '.' });
if (m_precision > 0)
{
writer.Write(
string.Join("/",
elements
.Reverse()
.Take(m_precision)
.Reverse()
)
);
return;
}
writer.Write(
string.Join("/",
elements
.Take(elements.Count() + m_precision)
)
);
}
开发者ID:baskard,项目名称:CloudWatchAppender,代码行数:35,代码来源:LoggerPatternConverter.cs
示例7: ConvertTestWithExceptionObject
public void ConvertTestWithExceptionObject()
{
var level = Level.Debug;
var writer = new StreamWriter(new MemoryStream());
var converter = new StructuredDataConverter();
Exception exception = null;
try
{
throw new Exception("test exception message");
}
catch (Exception ex)
{
exception = ex;
}
ILoggerRepository logRepository = Substitute.For<ILoggerRepository>();
var evt = new LoggingEvent(typeof(StructuredDataConverterTests), logRepository, "test logger", level, "test message", exception);
evt.Properties["log4net:StructuredDataPrefix"] = "[email protected]";
evt.Properties["log4net:syslog-exception-log"] = "file://some-log-file/who/cares";
converter.Format(writer, evt);
writer.Flush();
var result = TestUtilities.GetStringFromStream(writer.BaseStream);
Assert.IsTrue(Regex.IsMatch(result, "\\[[email protected] EventSeverity=\"DEBUG\" ExceptionSource=\"syslog4net\\.Tests\" ExceptionType=\"System\\.Exception\" ExceptionMessage=\"test exception message\" ExceptionMethodName=\"Void syslog4net\\.Tests\\.Converters\\.StructuredDataConverterTests\\.ConvertTestWithExceptionObject\\(\\)\" ExceptionFileName=\".*?StructuredDataConverterTests\\.cs\" ExceptionLineNumber=\"\\d+\" EventLog=\"file://some-log-file/who/cares\"\\]"));
}
开发者ID:Cayan-LLC,项目名称:syslog4net,代码行数:31,代码来源:StructuredDataConverterTests.cs
示例8: AddProperties
private void AddProperties(object logSource, Exception exception, LoggingEvent loggingEvent)
{
loggingEvent.Properties["UserName"] = GetUserName();
try
{
ContextProperties contextProperties = _contextService.GetContextProperties();
if (contextProperties != null)
{
try
{
loggingEvent.Properties["UserAgent"] = contextProperties.UserAgent;
loggingEvent.Properties["RemoteHost"] = contextProperties.RemoteHost;
loggingEvent.Properties["Path"] = contextProperties.Path;
loggingEvent.Properties["Query"] = contextProperties.Query;
loggingEvent.Properties["RefererUrl"] = contextProperties.Referrer;
loggingEvent.Properties["RequestId"] = contextProperties.RequestId;
loggingEvent.Properties["SessionId"] = contextProperties.SessionId;
}
catch (Exception)
{
}
}
loggingEvent.Properties["ExceptionType"] = exception == null ? "" : exception.GetType().ToString();
loggingEvent.Properties["ExceptionMessage"] = exception == null ? "" : exception.Message;
loggingEvent.Properties["ExceptionStackTrace"] = exception == null ? "" : exception.StackTrace;
loggingEvent.Properties["LogSource"] = logSource.GetType().ToString();
}
catch (Exception ex)
{
var type = typeof(Log4NetLoggingService);
var logger = LogManager.GetLogger(type);
logger.Logger.Log(type, Level.Fatal, "Exception when extracting properties: " + ex.Message, ex);
}
}
开发者ID:FCMA-OSS,项目名称:RewardRecognition,代码行数:35,代码来源:Log4NetLoggingService.cs
示例9: AppendLoopOnAppenders
/// <summary>
/// Append on on all attached appenders.
/// </summary>
/// <param name="loggingEvent">The event being logged.</param>
/// <returns>The number of appenders called.</returns>
/// <remarks>
/// <para>
/// Calls the <see cref="IAppender.DoAppend" /> method on all
/// attached appenders.
/// </para>
/// </remarks>
public int AppendLoopOnAppenders(LoggingEvent loggingEvent)
{
if (loggingEvent == null)
{
throw new ArgumentNullException("loggingEvent");
}
// m_appenderList is null when empty
if (m_appenderList == null)
{
return 0;
}
if (m_appenderArray == null)
{
m_appenderArray = m_appenderList.ToArray();
}
foreach(IAppender appender in m_appenderArray)
{
try
{
appender.DoAppend(loggingEvent);
}
catch(Exception ex)
{
LogLog.Error("AppenderAttachedImpl: Failed to append to appender [" + appender.Name + "]", ex);
}
}
return m_appenderList.Count;
}
开发者ID:BackupTheBerlios,项目名称:ch3etah-svn,代码行数:42,代码来源:AppenderAttachedImpl.cs
示例10: Append
protected override void Append(LoggingEvent loggingEvent)
{
if (FilterEvent(loggingEvent))
{
_pendingTasks.Enqueue(loggingEvent);
}
}
开发者ID:jjchiw,项目名称:gelf4net,代码行数:7,代码来源:AsyncGelfAmqpAppender.cs
示例11: Append
protected override void Append(LoggingEvent loggingEvent)
{
try
{
Log _log = new Log();
string message = RenderLoggingEvent(loggingEvent);
string maquina = Dns.GetHostName();
IPAddress[] ip = Dns.GetHostAddresses(maquina);
_log.IdCorrelacao = LogicalThreadContext.Properties["CorrelationId"].ToString();
_log.DataHora = DateTime.Now;
_log.Ip = ip[1].ToString();
_log.Maquina = maquina;
_log.Usuario = loggingEvent.Identity;
_log.SistemaOrigem = _sourcesystem;
_log.Tipo = loggingEvent.Level.Name;
_log.Dados = message;
//Salva Fila Assincrono
if (_salvar == null)
{
_salvar = new SaveAsynchronous(ConsumeAsynchronous, "ThreadLog", System.Threading.ThreadPriority.Normal, true);
}
_salvar.Save(_log);
}
catch (Exception ex)
{
//TODO: Erro na gravacao da fila???
}
}
开发者ID:angelcdz,项目名称:Sirius,代码行数:31,代码来源:AppenderLogger.cs
示例12: Format
public override void Format(TextWriter writer, LoggingEvent loggingEvent) {
// check arguments
if (loggingEvent == null) return;
if (loggingEvent.MessageObject == null && loggingEvent.RenderedMessage == null) return;
// get logger id
string loggerId = loggingEvent.GetLoggingEventProperty("__objectId");
// prepare stuff
string message = loggingEvent.MessageObject == null ? loggingEvent.RenderedMessage : loggingEvent.MessageObject.ToString();
string info = loggingEvent.GetLoggingEventProperty("__extendedInfo");
if (info != null) {
message = message + " " + info;
}
string[] lines = message.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
string header = string.Format("{0} [{1}] ({3}|{4}|{5}) {2} : ", loggingEvent.TimeStamp.ToString("dd-MM-yyyy hh:mm:ss,fff"), loggingEvent.Level.DisplayName.PadLeft(5, ' '), this.LoggerName(loggingEvent.LoggerName), Thread.CurrentThread.GetHashCode().ToString(CultureInfo.InvariantCulture).PadLeft(2, ' '), loggerId.PadLeft(2), Thread.CurrentPrincipal != null ? Thread.CurrentPrincipal.Identity.Name : "unknown");
const string FILLER = "\t";
for (int i = 0; i < lines.Length; i++) {
if (i == 0) {
writer.Write(header);
} else {
writer.Write(FILLER);
}
writer.WriteLine(lines[i]);
}
}
开发者ID:StevenArnauts,项目名称:appserver,代码行数:27,代码来源:TextLayout.cs
示例13: Append
override protected void Append(LoggingEvent loggingEvent)
{
object messageObject = loggingEvent.MessageObject;
if (messageObject != null && !(messageObject is string))
{
Type messageType = messageObject.GetType();
if (m_expandProperties)
{
// Get all public instance properties
foreach(PropertyInfo propertyInfo in messageType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (propertyInfo.CanRead)
{
loggingEvent.Properties[propertyInfo.Name] = propertyInfo.GetValue(messageObject, null);
}
}
}
if (m_expandFields)
{
// Get all public instance fields
foreach(FieldInfo fieldInfo in messageType.GetFields(BindingFlags.Instance | BindingFlags.Public))
{
loggingEvent.Properties[fieldInfo.Name] = fieldInfo.GetValue(messageObject);
}
}
}
// Delegate to base class which will forward
base.Append(loggingEvent);
}
开发者ID:ittray,项目名称:LocalDemo,代码行数:33,代码来源:MessageObjectExpanderAppender.cs
示例14: Format
public override void Format(TextWriter textWriter, LoggingEvent loggingEvent)
{
base.Format(textWriter, loggingEvent);
if (loggingEvent.ExceptionObject != null)
textWriter.Write(Environment.StackTrace);
}
开发者ID:haseeb200,项目名称:Work-Flow-App,代码行数:7,代码来源:TracingLayout.cs
示例15: Convert
/// <summary>
/// Convert the pattern to the rendered message
/// </summary>
/// <param name="writer"><see cref="T:System.IO.TextWriter" /> that will receive the formatted result.</param>
/// <param name="loggingEvent">the event being logged</param>
/// <remarks>
/// Render the <see cref="M:log4net.Layout.Pattern.NamedPatternConverter.GetFullyQualifiedName(log4net.Core.LoggingEvent)" /> to the precision
/// specified by the <see cref="P:log4net.Util.PatternConverter.Option" /> property.
/// </remarks>
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
string text = this.GetFullyQualifiedName(loggingEvent);
if (this.m_precision <= 0 || text == null || text.Length < 2)
{
writer.Write(text);
}
else
{
int num = text.Length;
string str = string.Empty;
if (text.EndsWith("."))
{
str = ".";
text = text.Substring(0, num - 1);
num--;
}
int num2 = text.LastIndexOf(".");
int num3 = 1;
while (num2 > 0 && num3 < this.m_precision)
{
num2 = text.LastIndexOf('.', num2 - 1);
num3++;
}
if (num2 == -1)
{
writer.Write(text + str);
}
else
{
writer.Write(text.Substring(num2 + 1, num - num2 - 1) + str);
}
}
}
开发者ID:JoeRall,项目名称:CloudWatchAppender,代码行数:43,代码来源:NamedPatternConverter.cs
示例16: Append
protected override void Append(LoggingEvent loggingEvent)
{
Debug.WriteLine("ClassOutline.Logging:" + loggingEvent.RenderedMessage);
dynamic tmp = null;
if (loggingEvent.ExceptionObject != null)
{
tmp = new
{
Message = loggingEvent.RenderedMessage,
};
}
else
{
tmp = new
{
Message = loggingEvent.RenderedMessage,
Exception = loggingEvent.ExceptionObject
};
}
var errorMessage = JsonConvert.SerializeObject(tmp);
ReportError(errorMessage);
}
开发者ID:stickleprojects,项目名称:ClassOutline,代码行数:27,代码来源:VisualStudioOutputLogger.cs
示例17: ParseBasicFields
protected void ParseBasicFields(LoggingEvent sourceLoggingEvent, Dictionary<string, object> resultDictionary)
{
resultDictionary["@timestamp"] = sourceLoggingEvent.TimeStamp.ToUniversalTime().ToString("O");
resultDictionary["LoggerName"] = sourceLoggingEvent.LoggerName;
resultDictionary["HostName"] = MachineName;
if (FixedFields.ContainsFlag(FixFlags.ThreadName))
{
resultDictionary["ThreadName"] = sourceLoggingEvent.ThreadName;
}
if (FixedFields.ContainsFlag(FixFlags.Domain))
{
resultDictionary["AppDomain"] = sourceLoggingEvent.Domain;
}
if (sourceLoggingEvent.Level != null)
{
resultDictionary["Level"] = sourceLoggingEvent.Level.DisplayName;
}
if (FixedFields.ContainsFlag(FixFlags.Identity))
{
resultDictionary["Identity"] = sourceLoggingEvent.Identity;
}
if (FixedFields.ContainsFlag(FixFlags.UserName))
{
resultDictionary["UserName"] = sourceLoggingEvent.UserName;
}
}
开发者ID:cdzhoubin,项目名称:log4stash,代码行数:31,代码来源:BasicLogEventFactory.cs
示例18: ConvertTestNoException
public void ConvertTestNoException()
{
var level = Level.Debug;
var testId = "9001";
var resultString = "[[email protected] MessageId=\"" + testId + "\" EventSeverity=\"" + level.DisplayName + "\"]";
var writer = new StreamWriter(new MemoryStream());
var converter = new StructuredDataConverter();
var props = new PropertiesDictionary();
props["MessageId"] = testId;
props["log4net:StructuredDataPrefix"] = "[email protected]";
// Additional tests using stack data is prevented as the converter class only pulls from LoggingEvent.GetProperties()
// The data behind this method is setup by log4net itself so testing stack usage would not really apply properly here
//ThreadContext.Stacks["foo"].Push("bar");
var evt = new LoggingEvent(new LoggingEventData() { Properties = props, Level = level });
converter.Format(writer, evt);
writer.Flush();
var result = TestUtilities.GetStringFromStream(writer.BaseStream);
Assert.AreEqual(resultString, result);
}
开发者ID:Cayan-LLC,项目名称:syslog4net,代码行数:25,代码来源:StructuredDataConverterTests.cs
示例19: Append
protected override void Append(LoggingEvent loggingEvent)
{
try
{
var config = ObjectFactory.GetInstance<IConfigRepository>();
if (!config.Get("LogToDatabase", false))
return;
using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
{
var logDO = new LogDO
{
Level = loggingEvent.Level.ToString(),
Message = loggingEvent.RenderedMessage,
Name = loggingEvent.LoggerName
};
uow.LogRepository.Add(logDO);
uow.SaveChanges();
}
}
catch (Exception)
{
//No reason to throw an error on our logging system...
}
}
开发者ID:alexed1,项目名称:dtrack,代码行数:25,代码来源:KwasantLogAppender.cs
示例20: Format
public override void Format(TextWriter writer, LoggingEvent loggingEvent)
{
var ctw = new CsvTextWriter(writer);
// write the starting quote for the first field
ctw.WriteQuote();
base.Format(ctw, loggingEvent);
}
开发者ID:AzarinSergey,项目名称:learn,代码行数:7,代码来源:CsvPatternLayout+.cs
注:本文中的log4net.Core.LoggingEvent类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论