本文整理汇总了C#中LogEvent类的典型用法代码示例。如果您正苦于以下问题:C# LogEvent类的具体用法?C# LogEvent怎么用?C# LogEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogEvent类属于命名空间,在下文中一共展示了LogEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public void Write(LogLevel level, LogEvent logEvent)
{
LogBuilder fluent;
switch (level)
{
case LogLevel.Trace:
fluent = _logger.Trace();
break;
case LogLevel.Info:
fluent = _logger.Info();
break;
case LogLevel.Warning:
fluent = _logger.Warn();
break;
case LogLevel.Error:
fluent = _logger.Error();
break;
case LogLevel.Critical:
fluent = _logger.Fatal();
break;
default:
throw new ApplicationException("Invalid log level");
}
if (!string.IsNullOrWhiteSpace(logEvent.Message))
fluent.Message(logEvent.Message);
if (logEvent.Exception != null)
fluent.Exception(logEvent.Exception);
foreach (var parameter in logEvent.Parameters)
{
fluent.Property(parameter.Key, parameter.Value);
}
fluent.Write();
}
示例2: Main
/// <summary>
/// This version works with the OpenEngS 3.0.0-Snapshot Framwork
/// </summary>
/// <param name="args">System Arguments</param>
static void Main(string[] args)
{
log4net.Config.BasicConfigurator.Configure();
ILog logger = LogManager.GetLogger(typeof(ExampleDomainConnector));
string destination = "tcp://localhost.:6549";
string domainName = "example";
logger.Info("Start Example wit the domain " + domainName);
IExampleDomainSoap11Binding localDomain = new ExampleDomainConnector();
IDomainFactory factory = DomainFactoryProvider.GetDomainFactoryInstance("3.0.0", destination, localDomain, EExceptionHandling.Retry);
//Register the connecter on the OpenEngSB
String serviceId = factory.CreateDomainService(domainName);
factory.RegisterConnector(serviceId, domainName);
IExampleDomainEventsSoap11Binding remotedomain = factory.getEventhandler<IExampleDomainEventsSoap11Binding>(domainName);
LogEvent lEvent = new LogEvent();
lEvent.name = "Example";
lEvent.level = "DEBUG";
lEvent.message = "remoteTestEventLog";
remotedomain.raiseEvent(lEvent);
logger.Info("Press enter to close the Connection");
Console.ReadKey();
factory.UnRegisterConnector(domainName);
factory.DeleteDomainService(domainName);
factory.StopConnection(domainName);
}
示例3: Emit
/// <summary>
/// Emit the provided log event to the sink.
/// </summary>
/// <param name="logEvent">The log event to write.</param>
public void Emit(LogEvent logEvent)
{
LogEventPropertyValue eventId;
logEvent.Properties.TryGetValue("EventId", out eventId);
LogEventPropertyValue hostName;
logEvent.Properties.TryGetValue("Host", out hostName);
LogEventPropertyValue url;
logEvent.Properties.TryGetValue("RequestPath", out url);
Message message = new Message(logEvent.RenderMessage(_formatProvider))
{
id = eventId?.ToString(),
hostname = hostName?.ToString(),
url = url?.ToString(),
QueryString = RequestQueryToQuery(logEvent),
Severity = LevelToSeverity(logEvent),
DateTime = logEvent.Timestamp.DateTime.ToUniversalTime(),
Detail = logEvent.Exception?.ToString(),
Data = PropertiesToData(logEvent),
};
// Convert to json
string messageJson = MessageToJson(message);
// Call ElmhaIO
HttpClient client = new HttpClient();
client.PostAsync([email protected]"https://elmah.io/api/v2/messages?logid={_logId}", new StringContent(messageJson, Encoding.UTF8, "application/json"));
}
示例4: AddLogEvent
public static void AddLogEvent(LogEvent logEvent)
{
if (!_activeLogEvents.Contains(logEvent))
{
_activeLogEvents.Add(logEvent);
}
}
示例5: Log
// Synchronous logging
public override void Log(LogEvent logEvent)
{
// Lock, to keep our colors from getting messed up
lock (_colorLock)
{
// Get a hold of the current colors
var oldForeground = Console.ForegroundColor;
var oldBackground = Console.BackgroundColor;
try
{
// Feedback loop prevention
var silent = logEvent != null && logEvent.Silent;
// Set the colors to our custom colors
Console.BackgroundColor = GetConsoleColor(logEvent, BackgroundColorMeta, ColorConfig.BackgroundColor, silent);
Console.ForegroundColor = GetConsoleColor(logEvent, ForegroundColorMeta, ColorConfig.ForegroundColor, silent);
// Write out our message
Console.Out.Write(Layout.FormatLogEvent(logEvent));
}
finally
{
// Make sure we reset our colors
Console.ForegroundColor = oldForeground;
Console.BackgroundColor = oldBackground;
}
}
}
示例6: LogEvent
void LogEvent(LogEvent eventInfo)
{
if (eventInfo.Level == LogEventLevel.Verbose)
{
verboses.Add(eventInfo);
}
if (eventInfo.Level == LogEventLevel.Debug)
{
debugs.Add(eventInfo);
}
if (eventInfo.Level == LogEventLevel.Fatal)
{
fatals.Add(eventInfo);
}
if (eventInfo.Level == LogEventLevel.Error)
{
errors.Add(eventInfo);
}
if (eventInfo.Level == LogEventLevel.Information)
{
informations.Add(eventInfo);
}
if (eventInfo.Level == LogEventLevel.Warning)
{
warns.Add(eventInfo);
}
}
示例7: Enrich
public void Enrich(LogEvent e, out string propertyName, out object propertyValue)
{
var frame = new StackFrame(4); //warning! this can change after refactoring
propertyName = "method";
MethodBase method = frame.GetMethod();
var sb = new StringBuilder();
sb.Append(method.DeclaringType.FullName);
sb.Append(".");
sb.Append(method.Name);
sb.Append("(");
bool isFirst = true;
foreach(ParameterInfo p in method.GetParameters())
{
if (!isFirst)
{
sb.Append(", ");
}
else
{
isFirst = false;
}
sb.Append(p.ParameterType.Name);
sb.Append(" ");
sb.Append(p.Name);
}
sb.Append(")");
propertyValue = sb.ToString();
}
示例8: WriteLine
protected override void WriteLine(string textLine, LogEvent logEvent)
{
if (logEvent.LogLevel == LogLevel.FatalError)
{
Android.Util.Log.Error(logEvent.AppName, textLine);
return;
}
if (logEvent.LogLevel == LogLevel.Error)
{
Android.Util.Log.Error(logEvent.AppName, textLine);
return;
}
if (logEvent.LogLevel == LogLevel.Warning)
{
Android.Util.Log.Warn(logEvent.AppName, textLine);
return;
}
if (logEvent.LogLevel == LogLevel.Info)
{
Android.Util.Log.Info(logEvent.AppName, textLine);
return;
}
if (logEvent.LogLevel == LogLevel.Debug)
{
Android.Util.Log.Debug(logEvent.AppName, textLine);
return;
}
if (logEvent.LogLevel == LogLevel.Verbose)
{
Android.Util.Log.Verbose(logEvent.AppName, textLine);
return;
}
}
示例9: LogBatchEntry
/// <summary>
/// Initializes a new instance of the <see cref="LogBatchEntry" /> class.
/// </summary>
/// <param name="log">The log.</param>
/// <param name="message">The message.</param>
/// <param name="logEvent">The log event.</param>
/// <param name="extraData">The extra data.</param>
public LogBatchEntry(ILog log, string message, LogEvent logEvent, object extraData)
{
Log = log;
Message = message;
LogEvent = logEvent;
ExtraData = extraData;
}
示例10: LogMessage
void LogMessage(string message, LogEvent logEvent)
{
if (logEvent == LogEvent.Error)
{
Errors.Add(message);
return;
}
if (logEvent == LogEvent.Warning)
{
Warnings.Add(message);
return;
}
if (logEvent == LogEvent.Info)
{
Informations.Add(message);
return;
}
if (logEvent == LogEvent.Debug)
{
Debugs.Add(message);
// ReSharper disable once RedundantJumpStatement
return;
}
}
示例11: Emit
public void Emit(LogEvent logEvent)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
lock (syncRoot)
{
if (disposed)
{
throw new ObjectDisposedException(ThisObjectName, "Cannot write to disposed file");
}
if (output == null)
{
return;
}
formatter.Format(logEvent, output);
output.Flush();
this.ActiveLogLevel = logEvent.Level;
if (output.BaseStream.Length > fileSizeLimitBytes)
{
sizeLimitReached = true;
}
}
}
示例12: Write
/// <summary>
/// Called when any message is written to the log.
/// </summary>
/// <param name="log">The log.</param>
/// <param name="message">The message.</param>
/// <param name="logEvent">The log event.</param>
/// <param name="extraData">The additional data.</param>
/// <param name="time">The time.</param>
protected override void Write(ILog log, string message, LogEvent logEvent, object extraData, System.DateTime time)
{
base.Write(log, message, logEvent, extraData, time);
switch (logEvent)
{
case LogEvent.Debug:
_eventSource.Debug(message);
break;
case LogEvent.Info:
_eventSource.Info(message);
break;
case LogEvent.Warning:
_eventSource.Warning(message);
break;
case LogEvent.Error:
_eventSource.Error(message);
break;
default:
throw new ArgumentOutOfRangeException("logEvent");
}
}
示例13: Log
public override void Log(LogEvent oEvent)
{
m_oEventLog.Source = this.AppName;
m_oEventLog.WriteEntry(oEvent.Message, GetEventEntryType(oEvent.Level), oEvent.ID);
//test exception
//throw new Exception("test exp from WindowsEventHandler class");
}
示例14: Write
protected override void Write(ILog log, string message, LogEvent logEvent, object extraData, LogData logData, DateTime time)
{
if (log.TargetType != typeof(TestLogListener))
{
return;
}
switch (logEvent)
{
case LogEvent.Debug:
DebugCount++;
break;
case LogEvent.Info:
InfoCount++;
break;
case LogEvent.Warning:
WarningCount++;
break;
case LogEvent.Error:
ErrorCount++;
break;
case LogEvent.Status:
StatusCount++;
break;
}
}
示例15: Create
/// <summary>
/// Creates a new SmtpLogEventBuilder based on the passed log event
/// </summary>
/// <param name="logEvent">The log event to use as a base</param>
/// <returns>A new instance of SmtpLogEventBuilder</returns>
public static EmailLogEventBuilder Create(LogEvent logEvent)
{
return new EmailLogEventBuilder
{
LogEvent = logEvent
};
}