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


C# NLog类代码示例

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


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

示例1: DisplayError

 private static void DisplayError(string error, NLog.Logger logger = null)
 {
     if (null != logger)
     {
         logger.Error(error);
     }
     else
     {
         Console.Error.WriteLine(error);
     }
 }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:11,代码来源:BinaryPackagerHelper.cs

示例2: GetExceptionDetails

        /// <summary>
        /// This expects a web context; without it, the method will exit early.
        /// </summary>
        /// <param name="logEvent"></param>
        /// <returns></returns>
        public static string GetExceptionDetails(NLog.LogEventInfo logEvent)
        {
            if (HttpContext.Current == null
                || HttpContext.Current.Request == null
                || HttpContext.Current.Server == null) { return ""; }

            var serverVariables = HttpContext.Current.Request.ServerVariables;
            var lastError = HttpContext.Current.Server.GetLastError();

            string errorMessage = (lastError == null) ? logEvent.FormattedMessage : lastError.InnerException.ToString();

            var errorDetails = new StringBuilder();

            errorDetails.AppendFormat("{0}<br /><br />", errorMessage);
            // This helps give meaningful data in the case of "File does not exist" errors
            errorDetails.AppendFormat("File Path: {0}<br /><br />", HttpContext.Current.Request.FilePath);

            // Stack trace
            if (logEvent.StackTrace != null)
                errorDetails.AppendFormat("<i>Stack Trace:</i><br />{0}<br /><br />", logEvent.StackTrace.ToString());
            else if (logEvent.Exception != null)
                errorDetails.AppendFormat("<i>Stack Trace:</i><br />{0}<br /><br />", logEvent.Exception.Message + logEvent.Exception.StackTrace.ToString());

            // Server variables
            errorDetails.AppendFormat("<i>Server Variables:</i><br />");

            foreach (String s in serverVariables.AllKeys)
                errorDetails.AppendFormat("<p><span>{0,-10}<span>: <b>{1}</b></p>", s, serverVariables[s]);

            return errorDetails.ToString();
        }
开发者ID:eiu165,项目名称:ProjectTracker,代码行数:36,代码来源:ExceptionHelper.cs

示例3: Write

 protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
 {
     if ( logEvent.LogEvent.Level > LogLevel.Warn && logEvent.LogEvent.Exception != null )
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(logEvent.LogEvent.Exception);
     }
 }
开发者ID:BernhardGlueck,项目名称:Wmc,代码行数:7,代码来源:ElmahTarget.cs

示例4: Write

        protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
        {
            base.Write(logEvent);

            if (LogReceived != null)
                LogReceived(logEvent);
        }
开发者ID:Chris-E-J-Ellis,项目名称:CardHunterBrowser,代码行数:7,代码来源:LogTarget.cs

示例5: CreateLogEventInfo

        private LogEventInfo CreateLogEventInfo(NLog.LogLevel level, string message, IDictionary<string, object> dictionary, Exception exception)
        {
            LogEventInfo logEvent = new LogEventInfo(level, _logger.Name, message);

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

            if (exception != null)
            {
                logEvent.Properties["error-source"] = exception.Source;
                if (exception.TargetSite != null)
                {
                    if (exception.TargetSite.DeclaringType != null)
                    {
                        logEvent.Properties["error-class"] = exception.TargetSite.DeclaringType.FullName;
                    }
                    logEvent.Properties["error-method"] = exception.TargetSite.Name;

                }
                logEvent.Properties["error-message"] = exception.Message;

                if (exception.InnerException != null)
                {
                    logEvent.Properties["inner-error-message"] = exception.InnerException.Message;
                }
            }

            return logEvent;
        }
开发者ID:Nybus-project,项目名称:Nybus,代码行数:31,代码来源:NLogLogger.cs

示例6: LumberjackMessageBuilder

 public LumberjackMessageBuilder(NLog.Logger logger, string source, string appId, string component)
 {
     Logger = logger;
     Source = source;
     AppId = appId;
     Component = component;
 }
开发者ID:zhekaby,项目名称:nlog.lumberjack,代码行数:7,代码来源:LumberjackMessageBuilder.cs

示例7: Write

 protected override void Write(NLog.Common.AsyncLogEventInfo[] logEvents)
 {
     foreach (var ev in logEvents)
     {
         NumEvents++;
     }
 }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:7,代码来源:MockLogTarget.cs

示例8: Write

        protected override void Write(NLog.Common.AsyncLogEventInfo logEvent)
        {
            base.Write(logEvent);

            if (RecieveLog != null)
                RecieveLog(logEvent);
        }
开发者ID:douglasg14b,项目名称:HelpScout-Metrics,代码行数:7,代码来源:NLogViewerTarget.cs

示例9: LoggerMark

		/// <summary>
		/// Instantiates an instance of the LoggerMark class.
		/// </summary>
		/// <param name="location">The location of the mark.</param>
		/// <param name="logger">The logger to log the mark to.</param>
		public LoggerMark(string location, NLog.Logger logger)
		{
			_id = _nextId++;
			_location = location;
			_logger = logger;
			_logger.Trace("Enter " + location + " : " + _id);
			_watch = Stopwatch.StartNew();
		}
开发者ID:colonij21,项目名称:TestR,代码行数:13,代码来源:LoggerMark.cs

示例10: PackageService

		public PackageService(
			IServerPackageRepository repository,
			IPackageAuthenticationService authenticationService,
			NLog.ILogger logger)
		{
			_serverRepository = repository;
			_authenticationService = authenticationService;
			_logger = logger;
		}
开发者ID:jholovacs,项目名称:NuGet,代码行数:9,代码来源:PackageService.cs

示例11: Write

 public static void Write(object element, int depth, NLog.Logger log)
 {
     if (log.IsTraceEnabled)
     {
         ObjectDumper dumper = new ObjectDumper(depth);
         dumper.WriteObject(null, element);
         log.Trace(dumper.builder);
     }
 }
开发者ID:andyhoyle,项目名称:Crucial.Framework,代码行数:9,代码来源:ObjectDumper.cs

示例12: DeployBatchRunner

		public DeployBatchRunner(NLog.Logger logger, ISystemSettings systemSettings, IDeployStateManager deployStateManager, IDeployRunner deployRunner, IDeployQueueManager deployQueueManager, IDeployRequestManager deployRequestManager, ICleanupManager cleanupManager)
		{
			_logger = DIHelper.VerifyParameter(logger);
			_systemSettings = DIHelper.VerifyParameter(systemSettings);
			_deployStateManager = DIHelper.VerifyParameter(deployStateManager);
			_deployRunner = DIHelper.VerifyParameter(deployRunner);
			_deployQueueManager = DIHelper.VerifyParameter(deployQueueManager);
			_deployRequestManager = DIHelper.VerifyParameter(deployRequestManager);
			_cleanupManager = DIHelper.VerifyParameter(_cleanupManager);
		}
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:10,代码来源:DeployBatchRunner.cs

示例13: LogEvent

 public LogEvent(NLog.LogEventInfo logEventInfo)
 {
     LoggerName = logEventInfo.LoggerName;
     TimeStamp = logEventInfo.TimeStamp;
     Level = logEventInfo.Level.ToString();
     LogMessage = logEventInfo.FormattedMessage;
     ToolTip = logEventInfo.FormattedMessage;
     Exception = logEventInfo.Exception;
     SetColors(logEventInfo);
 }
开发者ID:douglasg14b,项目名称:HelpScout-Metrics,代码行数:10,代码来源:LogEvent.cs

示例14: Write

		protected override void Write(NLog.LogEventInfo logEvent) {
			var	msg = AppendException(logEvent.FormattedMessage, logEvent.Exception);
			
			_buffer.Add(new LogMessage {
				Level = logEvent.Level,
				Message = msg,
				Source = logEvent.LoggerName,
				Timestamp = logEvent.TimeStamp
			});	
		}
开发者ID:santosh-mnrec,项目名称:AzurePlot,代码行数:10,代码来源:ViewableLogTarget.cs

示例15: Append

        protected override void Append(StringBuilder builder, NLog.LogEventInfo logEvent)
        {
            var actionName = string.Empty;
            if (HttpContext.Current != null)
            {
                actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString();
            }

            builder.Append(actionName);
        }
开发者ID:WiliamWu,项目名称:Api-Sample,代码行数:10,代码来源:ActionLayoutRenderer.cs


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