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


C# LogEvent类代码示例

本文整理汇总了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();
            }
开发者ID:WalnutBrain,项目名称:Core,代码行数:34,代码来源:NlogLoggerProvider.cs

示例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);
        }
开发者ID:ChristophGr,项目名称:loom-csharp,代码行数:31,代码来源:Program.cs

示例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"));
        }
开发者ID:nnyegaard,项目名称:serilog-sinks-elmahio,代码行数:34,代码来源:ElmahIOSink.cs

示例4: AddLogEvent

 public static void AddLogEvent(LogEvent logEvent)
 {
     if (!_activeLogEvents.Contains(logEvent))
     {
         _activeLogEvents.Add(logEvent);
     }
 }
开发者ID:sungaila,项目名称:uebersetzerbauSWP,代码行数:7,代码来源:Logger.cs

示例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;
                }
            }
        }
开发者ID:ivanpointer,项目名称:NuLog,代码行数:30,代码来源:ColorConsoleTarget.cs

示例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);
     }
 }
开发者ID:Fody,项目名称:Anotar,代码行数:27,代码来源:SerilogTests.cs

示例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();
        }
开发者ID:aloneguid,项目名称:logmagic,代码行数:32,代码来源:MethodNameEnricher.cs

示例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;
			}
		}
开发者ID:zelk,项目名称:straaw,代码行数:33,代码来源:LogcatLogWriter.cs

示例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;
 }
开发者ID:JaysonJG,项目名称:Catel,代码行数:14,代码来源:LogBatchEntry.cs

示例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;
        }

    }
开发者ID:Fody,项目名称:Anotar,代码行数:25,代码来源:CatelTests.cs

示例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;
                }
            }
        }
开发者ID:Peymanmi,项目名称:Serilog.Sinks.RollingFile.Extension,代码行数:27,代码来源:SizeLimitedFileSink.cs

示例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");
            }
        }
开发者ID:justdude,项目名称:DbExport,代码行数:34,代码来源:EtwLogListener.cs

示例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");
 }
开发者ID:Jusharra,项目名称:RMS,代码行数:7,代码来源:WindowsEventHandler.cs

示例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;
                }
            }
开发者ID:Catel,项目名称:Catel,代码行数:30,代码来源:LogManagerTest.cs

示例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
     };
 }
开发者ID:ivanpointer,项目名称:NuLog,代码行数:12,代码来源:EmailLogEventBuilder.cs


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