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

C# NLog类代码示例

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

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



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


示例16: DeployBatchParallelRunner

		public DeployBatchParallelRunner(NLog.Logger logger, ISystemSettings systemSettings, IDeployStateManager deployStateManager, IDeployQueueManager deployQueueManager, IDeployRequestManager deployRequestManager, IDeploymentPlanBuilder deploymentPlanBuilder, IDIFactory diFactory, ICleanupManager cleanupManager)
		{
			_logger = DIHelper.VerifyParameter(logger);
			_systemSettings = DIHelper.VerifyParameter(systemSettings);
			_deployStateManager = DIHelper.VerifyParameter(deployStateManager);
			_deployQueueManager = DIHelper.VerifyParameter(deployQueueManager);
			_deployRequestManager = DIHelper.VerifyParameter(deployRequestManager);
			_deploymentPlanBuilder = DIHelper.VerifyParameter(deploymentPlanBuilder);
			_diFactory = DIHelper.VerifyParameter(diFactory);
			_cleanupManager = DIHelper.VerifyParameter(cleanupManager);
		}
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:11,代码来源:DeployBatchParallelRunner.cs


示例17: IndicateNewActivity

        /// <summary>
        /// Indicates that new log information has been received.
        /// </summary>
        /// <param name="log">The log.</param>
        public void IndicateNewActivity(NLog.Common.AsyncLogEventInfo log)
        {
            this.logs.Add(log.LogEvent);
            NotifyOfPropertyChange(() => Logs);

            if (!this.IsActive)
            {
                HasUncheckedActivity = true;
                NotifyOfPropertyChange(() => HasUncheckedActivity);
            }
        }
开发者ID:Chris-E-J-Ellis,项目名称:CardHunterBrowser,代码行数:15,代码来源:LoggerViewModel.cs


示例18: CheckPoint

 public void CheckPoint(NLog.Logger logger, string name = null)
 {
     CheckPoint(name);
     DateTime lastTime;
     if (currentPointsList.Count > 1)
         lastTime = currentPointsList[currentPointsList.Count - 2].Time;
     else
         lastTime = currentGroupLevels.Last().GroupStartTime.Value;
     logger.Debug("Замер производительности [{0}] +{1} секунд.", currentPointsList.Last().Name,
                 (currentPointsList.Last().Time - lastTime).TotalSeconds);
 }
开发者ID:QualitySolution,项目名称:QSProjects,代码行数:11,代码来源:PerformanceHelper.cs


示例19: ConfigureLogger

 private void ConfigureLogger(NLog.LogLevel nlogLogLevel)
 {
     var config = new LoggingConfiguration();
     _target = new MemoryTarget {Layout = "${level:uppercase=true}|${message}|${exception}"};
     config.AddTarget("memory", _target);
     var loggingRule = new LoggingRule("*", NLog.LogLevel.Trace, _target);
     loggingRule.DisableLoggingForLevel(nlogLogLevel);
     config.LoggingRules.Add(loggingRule);
     LogManager.Configuration = config;
     _sut = new NLogLogProvider().GetLogger("Test");
 }
开发者ID:bartelink,项目名称:LibLog,代码行数:11,代码来源:NLogLogProviderLoggingDisabedTests.cs


示例20: UsersController

        public UsersController(IUOW uow, NLog.ILogger logger, ApplicationRoleManager roleManager, ApplicationSignInManager signInManager, ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
        {
            _logger = logger;
            _roleManager = roleManager;
            _signInManager = signInManager;
            _userManager = userManager;
            _authenticationManager = authenticationManager;
            _uow = uow;

            _logger.Debug("InstanceId: " + _instanceId);
        }
开发者ID:egaia,项目名称:ASP.NET-Tournament.Manager,代码行数:11,代码来源:UsersController.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# NLogEx.LoggerEx类代码示例发布时间:2022-05-24
下一篇:
C# NHtmlUnit类代码示例发布时间: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