• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LogEvent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



LogEvent类属于命名空间,在下文中一共展示了LogEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: UpdateConsoleColors

        private static void UpdateConsoleColors(LogEvent logEvent)
        {
            var colorSet = ColorSets[logEvent];

            Console.BackgroundColor = colorSet.Background;
            Console.ForegroundColor = colorSet.Foreground;
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:7,代码来源:ConsoleLogListener.cs


示例17: 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 extra data.</param>
        protected override void Write(ILog log, string message, LogEvent logEvent, object extraData)
        {
            string consoleMessage = string.Format("{0} => [{1}] {2}", DateTime.Now.ToString("hh:mm:ss:fff"),
                logEvent.ToString().ToUpper(), message);

#if NETFX_CORE
            System.Diagnostics.Debug.WriteLine(consoleMessage);
#elif WINDOWS_PHONE
            System.Diagnostics.Debug.WriteLine(consoleMessage);
#elif SL4 || SL5
            if (InitializeConsole())
            {
                _dispatcher.BeginInvoke(() => _console.InvokeSelf(consoleMessage));
            }
#elif NET
            switch (logEvent)
            {
                case LogEvent.Debug:
                    System.Diagnostics.Trace.WriteLine(consoleMessage);
                    break;

                case LogEvent.Info:
                    System.Diagnostics.Trace.TraceInformation(consoleMessage);
                    break;

                case LogEvent.Warning:
                    System.Diagnostics.Trace.TraceWarning(consoleMessage);
                    break;

                case LogEvent.Error:
                    System.Diagnostics.Trace.TraceError(consoleMessage);
                    break;
            }
#endif
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:42,代码来源:DebugLogListener.cs


示例18: WriteLine

		protected override void WriteLine(string textLine, LogEvent logEvent)
		{
			if (_activity == null)
				return;

			_activity.RunOnUiThread(() =>
			{
			    try
			    {
                    var adBuilder = new AlertDialog.Builder(_activity);
                    adBuilder.SetTitle(string.Format("LogWriter: {0}", logEvent.Logger.LoggingType.Name));
                    adBuilder.SetMessage(textLine);
                    adBuilder.SetNegativeButton("OK", (s, e) =>
                    {
                        var alertDialog = s as AlertDialog;
                        if (alertDialog != null)
                        {
                            alertDialog.Dismiss();
                            alertDialog.Cancel();
                        }
                    });

                    adBuilder.Create().Show();
			    }
			    catch (Exception e)
			    {
                    // TODO detta måste fixas
			        // something went terribly wrong
			    }
				
			});
		}
开发者ID:zelk,项目名称:straaw,代码行数:32,代码来源:DroidInformUserLogWriter.cs


示例19: Log

 public override void Log(LogEvent logEvent)
 {
     lock (_listLock)
     {
         _logEvents.Add(logEvent);
     }
 }
开发者ID:ivanpointer,项目名称:NuLog,代码行数:7,代码来源:ListTarget.cs


示例20: WriteToFile

        private void WriteToFile(LogEvent logEvent)
        {
            lock (this.syncRoot)
            {
                if (this.disposed)
                {
                    throw new ObjectDisposedException(ThisObjectName, "The rolling file sink has been disposed");
                }

                var resetSequence = currentSink.LogFile.Date.Date != DateTime.UtcNow.Date;

                if (currentSink.EnableLevelLogging && currentSink.ActiveLogLevel != logEvent.Level)
                {
                    currentSink = NextSizeLimitedFileSink(resetSequence, logEvent.Level);
                }

                if (currentSink.SizeLimitReached || resetSequence)
                {
                    currentSink = NextSizeLimitedFileSink(resetSequence, logEvent.Level);
                    ApplyRetentionPolicy(roller.LogFileDirectory);
                }

                if (this.currentSink != null)
                {
                    this.currentSink.Emit(logEvent);
                }
            }
        }
开发者ID:Peymanmi,项目名称:Serilog.Sinks.RollingFile.Extension,代码行数:28,代码来源:SizeRollingFileSink.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LogEventInfo类代码示例发布时间:2022-05-24
下一篇:
C# LogEntryType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap