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


C# NLog.LogEventInfo类代码示例

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


LogEventInfo类属于NLog命名空间,在下文中一共展示了LogEventInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Log

        public void Log(LogLevel level, string message, params object[] arguments)
        {
            var info = new LogEventInfo(GetLevel(level), Key, message);
            info.Parameters = arguments;

            LogManager.GetLogger(Key).Log(info);
        }
开发者ID:samuelabj,项目名称:EpisodeTracker,代码行数:7,代码来源:Logger.cs

示例2: Write

        /// <summary>
        /// Format and output logvent
        /// </summary>
        /// <param name="logEvent">If caller is NLogConnector, <paramref name="logEvent"/></param>.properties will have a complete set of values of HashTag.Diagnostics.LogEvent
        protected override void Write(LogEventInfo logEvent)
        {
            var msg = new Dictionary<object, object>();
            if (logEvent.Exception != null)
            {
                msg["exception"] = logEvent.Exception;
            }

            if (logEvent.HasStackTrace && logEvent.StackTrace != null)
            {
                msg["stackTrace"] = logEvent.StackTrace;
            }

            if (logEvent.UserStackFrame != null)
            {
                msg["userStackFrame"] = logEvent.UserStackFrame;
                msg["userStackFrameIndex"] = logEvent.UserStackFrameNumber;
            }

            foreach(var prop in logEvent.Properties)
            {
                msg[prop.Key] = prop.Value;
            }

            var id = msg["UUID"].ToString();

            var s = JsonConvert.SerializeObject(msg,Formatting.Indented);
            string fileName = Path.Combine(dropFolder, id.ToString()) + ".log";
            File.WriteAllText(fileName, s);
        }
开发者ID:HashTagDotNet,项目名称:EventLogger,代码行数:34,代码来源:NLogSplunkTarget.cs

示例3: Log

 public static void Log(string loggerName, LogLevel logLevel, string eventID, string message)
 {
     LogEventInfo logEvent = new LogEventInfo(logLevel, _logger.Name, message);
     logEvent.Properties["EventID"] = eventID;
     logEvent.Properties["LoggerName"] = loggerName;
     _logger.Log(typeof(EventLogger), logEvent);
 }
开发者ID:majilik,项目名称:RecruitmentSystem,代码行数:7,代码来源:EventLogger.cs

示例4: CreateLogDocument

        /// <summary>
        /// The create log document.
        /// </summary>
        /// <param name="logEvent">
        /// The log event.
        /// </param>
        /// <returns>
        /// The <see cref="Document"/>.
        /// </returns>
        private Document CreateLogDocument(LogEventInfo logEvent)
        {
            var log = new Document();
            log["Id"] = logEvent.SequenceID;
            log["TimeStamp"] = logEvent.TimeStamp;
            log["Level"] = logEvent.Level.ToString();
            log["Message"] = logEvent.Message;
            log["UserStackFrameNumber"] = logEvent.UserStackFrameNumber;
            if (logEvent.UserStackFrame != null)
            {
                log["FileName"] = logEvent.UserStackFrame.GetFileName();
                log["FileLineNumber"] = logEvent.UserStackFrame.GetFileLineNumber();
                log["FileColumnNumber"] = logEvent.UserStackFrame.GetFileColumnNumber();
                log["MethodName"] = logEvent.UserStackFrame.GetMethod().Name;
            }

            if (logEvent.Exception != null)
            {
                log["ExceptionMessage"] = logEvent.Exception.Message;
                log["ExceptionHResult"] = logEvent.Exception.HResult;
                log["ExceptionStackTrace"] = logEvent.Exception.StackTrace;
                log["ExceptionSource"] = logEvent.Exception.Source;
            }

            log["UserEmail"] = logEvent.Properties["UserEmail"].ToString();
            log["OrderId"] = logEvent.Properties["OrderId"].ToString();
            log["PackageId"] = logEvent.Properties["PackageId"].ToString();
            log["TransactionId"] = logEvent.Properties["TransactionId"].ToString();

            return log;
        }
开发者ID:Naviam,项目名称:Shop-Any-Ware,代码行数:40,代码来源:NLogAmazonDynamoDbTarget.cs

示例5: Check

 protected override FilterResult Check(LogEventInfo ev)
 {
     if (ev.TimeStamp.Hour >= FromHour && ev.TimeStamp.Hour <= ToHour)
         return Result;
     else
         return FilterResult.Neutral;
 }
开发者ID:CharlieBP,项目名称:NLog,代码行数:7,代码来源:MyFirstFilter.cs

示例6: Test4

 public void Test4()
 {
     Layout l = new Layout("${rot13:${event-context:aaa}}");
     LogEventInfo lei = new LogEventInfo(LogLevel.Info, "aaa", "bbb");
     lei.Context["aaa"] = "HELLO";
     Assert.AreEqual("URYYB", l.GetFormattedMessage(lei));
 }
开发者ID:tdhieu,项目名称:openvss,代码行数:7,代码来源:Rot13Tests.cs

示例7: Append

        /// <summary>
        /// Renders the specified environmental information and appends it to the specified <see cref="T:System.Text.StringBuilder"/>.
        /// </summary>
        /// <param name="builder">The <see cref="T:System.Text.StringBuilder"/> to append the rendered data to.</param><param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            try
            {
                if (HttpContext.Current == null)
                    return;

                var context = new HttpContextWrapper(HttpContext.Current);

                if (context.Request.RequestContext == null)
                    return;

                var work = context.Request.RequestContext.GetWorkContext();
                if (work == null)
                    return;

                ShellSettings settings;
                if (!work.TryResolve(out settings))
                    return;

                builder.Append("Tenant:");
                builder.AppendLine(settings.Name);
            }
            catch
            {
            }
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:31,代码来源:TenantLayoutRenderer.cs

示例8: Append

        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var record =  logEvent.Properties[NLogTraceWriter.RecordKey] as TraceRecord;

            if (record != null)
            {
                if (Operation)
                    builder.Append(record.Operation);

                if (Status)
                    builder.Append(record.Status.ToString());

                if (StatusCode)
                    builder.Append(Convert.ToInt32(record.Status));

                if (RequestId)
                    builder.Append(record.RequestId);

                if (Operator)
                    builder.Append(record.Operator);

                if (Kind)
                    builder.Append(record.Kind.ToString());

                if (AcceptType)
                    builder.Append(record.Request.Headers.Accept.ToString());

                if (Host)
                    builder.Append(record.Request.Headers.Host);
            }
        }
开发者ID:kfrancis,项目名称:webapi.nlog,代码行数:31,代码来源:WebApiTraceRenderer.cs

示例9: Write

 protected override void Write(LogEventInfo logEvent)
 {
     if (logEvent.Level >= LogLevel.Warn)
     {
         _logs.Add(logEvent);
     }
 }
开发者ID:keep3r,项目名称:Sonarr,代码行数:7,代码来源:ExceptionVerification.cs

示例10: Append

        protected override void Append( StringBuilder builder, LogEventInfo logEvent )
        {
            object value;
            if (!logEvent.Properties.TryGetValue( NLogTraceWriter.RecordKey, out value ))
                return;

            var record = value as TraceRecord;
            if (record == null)
                return;


            if (Operation)
                builder.Append( record.Operation );

            if (Status)
                builder.Append( record.Status.ToString() );

            if (StatusCode)
                builder.Append( Convert.ToInt32( record.Status ) );

            if (RequestId)
                builder.Append( record.RequestId );

            if (Operator)
                builder.Append( record.Operator );

            if (Kind)
                builder.Append( record.Kind.ToString() );

        }
开发者ID:mpaschetto,项目名称:webapi.nlog,代码行数:30,代码来源:WebApiTraceRenderer.cs

示例11: Write

    protected override void Write(LogEventInfo logEvent)
    {
      try
      {
        string message = Layout.Render(logEvent);

        // echo to debug
        Debug.WriteLine(message);

        ScriptObject scriptMethod = null;

        if (logEvent.Level == LogLevel.Info)
          scriptMethod = _debugInfo;
        else if (logEvent.Level == LogLevel.Warn)
          scriptMethod = _debugWarn;
        else if (logEvent.Level == LogLevel.Error)
          scriptMethod = _debugError;

        if (scriptMethod == null)
          scriptMethod = _debugLog;

        if (scriptMethod == null)
          return;

        // thread safe
        Deployment.Current.Dispatcher.BeginInvoke(() => 
          scriptMethod.InvokeSelf(message));
      }
      catch (Exception ex)
      {
        Debug.WriteLine("Error calling debug.log function: " + ex);
      }
    }
开发者ID:modulexcite,项目名称:LoreSoft.Shared,代码行数:33,代码来源:BrowserConsoleTarget.cs

示例12: Write

        protected override void Write(LogEventInfo logEventInfo)
        {
            if (DocumentStore == null)
                DocumentStore = DependencyManager.GetInstance<IRavenDbContext>().DocumentStore;

            var logEvent = new LogEvent
            {
                FormattedMessage = logEventInfo.FormattedMessage,
                Level = logEventInfo.Level.Name,
                TimeStamp = logEventInfo.TimeStamp
            };
            // Set exceptions
            if (logEventInfo.Exception != null)
            {
                logEvent.Exception = logEventInfo.Exception.StackTrace;
                if (logEventInfo.Exception.InnerException != null)
                {
                    logEvent.InnerException = logEventInfo.Exception.InnerException.Message + "<br/>" + logEventInfo.Exception.InnerException.StackTrace;
                }
            }

            using (var session = DocumentStore.OpenSession())
            {
                session.Store(logEvent);
                session.SaveChanges();
            }
        }
开发者ID:jessetinell,项目名称:imenyn.se,代码行数:27,代码来源:NLogRavenDbTarget.cs

示例13: Info

        public static LogEventInfo Info(string loggerName, string message)
        {
            LogEventInfo evt = new LogEventInfo(LogLevel.Info, loggerName, message);
            evt.Properties["message"] = message;

            return evt;
        }
开发者ID:dublow,项目名称:MagicPlaylist,代码行数:7,代码来源:LoggerCreator.cs

示例14: MetricsCollector

        public MetricsCollector()
        {
            var config = ConfigurationManager.GetSection("CollectdWinConfig") as CollectdWinConfig;
            if (config == null)
            {
                LogEventInfo logEvent = new LogEventInfo(LogLevel.Error, Logger.Name, "Cannot get configuration section");
                logEvent.Properties.Add("EventID", ErrorCodes.ERROR_CONFIGURATION_EXCEPTION);
                Logger.Log(logEvent);
                return;
            }

            _runReadThread = false;
            _runWriteThread = false;

            var registry = new PluginRegistry();
            _plugins = registry.CreatePlugins();

            _interval = config.GeneralSettings.Interval;
            if (_interval <= 10)
                _interval = 10;

            _timeout = config.GeneralSettings.Timeout;
            if (_timeout <= _interval)
                _timeout = _interval*3;

            bool storeRates = config.GeneralSettings.StoreRates;

            _aggregator = new Aggregator(_timeout, storeRates);

            _collectedValueQueue = new Queue<CollectableValue>();
            _queueLock = new Object();
        }
开发者ID:Netuitive,项目名称:collectdwin,代码行数:32,代码来源:MetricsCollector.cs

示例15: CreateToolWindow

        private Window CreateToolWindow(IDockableUserControl control)
        {
            object userControlObject = null;
            Window toolWindow;
            try
            {
                _logger.Trace("Loading \"{0}\" ClassId {1}", control.Caption, control.ClassId);
                toolWindow = _vbe.Windows.CreateToolWindow(_addin, _DockableWindowHost.RegisteredProgId,
                    control.Caption, control.ClassId, ref userControlObject);
            }
            catch (COMException exception)
            {
                var logEvent = new LogEventInfo(LogLevel.Error, _logger.Name, "Error Creating Control");
                logEvent.Exception = exception;
                logEvent.Properties.Add("EventID", 1);

                _logger.Error(logEvent);
                return null; //throw;
            }
            catch (NullReferenceException exception)
            {
                Debug.Print(exception.ToString());
                return null; //throw;
            }

            var userControlHost = (_DockableWindowHost)userControlObject;
            toolWindow.Visible = true; //window resizing doesn't work without this

            EnsureMinimumWindowSize(toolWindow);

            toolWindow.Visible = false; //hide it again

            userControlHost.AddUserControl(control as UserControl);
            return toolWindow;
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:35,代码来源:DockableToolwindowPresenter.cs


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