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


C# Logger.Log方法代码示例

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


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

示例1: LogProgressMessage

        private static void LogProgressMessage(Logger logger, LogLevel level, string message)
        {
            var logEvent = new LogEventInfo(level, logger.Name, message);
            logEvent.Properties.Add("Status", "");

            logger.Log(logEvent);
        }
开发者ID:BubbaFatAss,项目名称:NzbDrone,代码行数:7,代码来源:LoggerExtensions.cs

示例2: MainForm

        public MainForm(string[] args)
        {
            InitializeComponent();

            logger = LogManager.GetLogger("");
            logger.Log(LogLevel.Info, "Starting up...");

            btnExit.Click += delegate { Exit(); };
            btnMinimize.Click += delegate { ShowHide(); };
            showHideToolStripMenuItem.Click += delegate { ShowHide(); };
            exitToolStripMenuItem.Click += delegate { Exit(); };
            notifyIcon.Text = Program.FullName;

            this.Text = Program.FullName;

            model = new Model(this.components, logger);
            HookModel();
            if (!model.Initialize())
            {
                this.Close();
                //Application.Exit();
            }

            PopulateFolderList();
            if (args.Length > 0)
            {
                if (!model.LoadTorrent(args[0]))
                    errorOnLoad = true;
            }
        }
开发者ID:chitza,项目名称:uDir,代码行数:30,代码来源:MainForm.cs

示例3: Log

 /// <summary>
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="logItem"></param>
 public static void Log(Logger logger, LogItem logItem)
 {
     if (!Constants.EnableNLog)
     {
         return;
     }
     switch (String.IsNullOrWhiteSpace(logItem.Message))
     {
         case true:
             if (logItem.Exception == null)
             {
                 return;
             }
             logger.LogException(logItem.LogLevel, logItem.Exception.Message, logItem.Exception);
             break;
         case false:
             if (logItem.Exception == null)
             {
                 logger.Log(logItem.LogLevel, logItem.Message);
             }
             else
             {
                 logger.LogException(logItem.LogLevel, logItem.Message, logItem.Exception);
             }
             break;
     }
 }
开发者ID:Yaguar666,项目名称:ffxivapp-common,代码行数:31,代码来源:Logging.cs

示例4: LogCleansedMessage

        private static void LogCleansedMessage(Logger logger, LogLevel level, string message)
        {
            message = Cleanse(message);

            var logEvent = new LogEventInfo(level, logger.Name, message);

            logger.Log(logEvent);
        }
开发者ID:Taloth,项目名称:NzbDrone,代码行数:8,代码来源:LoggerCleansedExtensions.cs

示例5: OnActionExecuting

 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     _logger = LogManager.GetLogger(filterContext.Controller.GetType().FullName);
     var eventInfo = new LogEventInfo(
         LogLevel.Info,
         _logger.Name,
         filterContext.Controller.GetType().Name + "." + filterContext.ActionDescriptor.ActionName);
     _logger.Log(eventInfo);
 }
开发者ID:Followin,项目名称:GameStore,代码行数:9,代码来源:LogAttribute.cs

示例6: Log

        private static void Log(Logger logger, LogLevel level, Exception exception, string extendedInfo, string format, params object[] args)
        {
            var eventInfo = exception == null ? new LogEventInfo(level, logger.Name, CultureInfo.InvariantCulture, format, args)
                : new LogEventInfo(level, logger.Name, CultureInfo.InvariantCulture, format, args, exception);

            if (extendedInfo != null)
                eventInfo.Properties["extendedInfo"] = extendedInfo;

            logger.Log(eventInfo);
        }
开发者ID:JAugustoGuimaraes,项目名称:Clutch,代码行数:10,代码来源:LoggerExtensions.cs

示例7: Log

        public static void Log(Logger logger, string message, Exception exception, LogLevel level = null)
        {
            if (logger == null)
            {
                return;
            }

            if (level == null)
            {
                level = LogLevel.Error;
            }

            logger.Log(level, message, exception);
        }
开发者ID:Bio2hazard,项目名称:talis.xivplugin.analyzer,代码行数:14,代码来源:LogHelper.cs

示例8: Initialize

        public static void Initialize(Action<NLogConfigurationApi> configure = null)
        {
            if (_logger != null)
                return;

            var config = new NLogConfigurationApi();
            if (configure != null)
            {
                configure(config);
            }

            _logger = SetupNLog(config);

            LoggingFacade.Initialize((level, message) =>
            {
                var nLogLevel = LevelToNLogLevel(level);
                _logger.Log(nLogLevel, message);
            });
        }
开发者ID:oylers,项目名称:Spiffy,代码行数:19,代码来源:NLog.cs

示例9: GenerateData

        static void GenerateData(Logger logger, DateTime init, DateTime @from)
        {
            var rand = new Random();
            var levels = new[] { LogLevel.Trace, LogLevel.Debug, LogLevel.Info, LogLevel.Warn };
            var messages = File.ReadAllLines(GetPath("messages.txt"));
            var tags = File.ReadAllText(GetPath("tags.txt")).Split(' ').Select(t => t.Trim(new[] { '.' })).ToArray();

            Console.WriteLine("Starting live data generation.");

            while (true)
            {
                logger.Log(levels[rand.Next(levels.Length)],
                    messages[rand.Next(messages.Length)],
                    tags: new[] { tags[rand.Next(tags.Length)] },
                    fields: new Dictionary<string, object>
                        {
                            { "curr-position", DateTime.UtcNow - init }
                        });

                Thread.Sleep(20);
            }
        }
开发者ID:cduhard,项目名称:semantic-logging,代码行数:22,代码来源:Program.cs

示例10: ProcessSolutionFiles

   private static void ProcessSolutionFiles(
 CurrentOperation operation,
 string[] conflictPaths,
 DirectoryInfo folder,
 Logger logger,
 string rootFolder)
   {
       foreach (var conflictPath in conflictPaths.Where(cp => cp.ToLowerInvariant().EndsWith(".sln")))
         {
       try
       {
         ProcessSolutionFile(operation, folder, logger, rootFolder, conflictPath);
       }
       catch (Exception e)
       {
         logger.Log(LogLevel.Error, e, "Failed to process solution file " + conflictPath);
       }
         }
   }
开发者ID:configit-open-source,项目名称:csmerge,代码行数:19,代码来源:CsMerge.cs

示例11: ProcessProjectFiles

        private static void ProcessProjectFiles(
      CurrentOperation operation,
      string[] conflictPaths,
      DirectoryInfo folder,
      Logger logger,
      string rootFolder )
        {
            var merger = new ProjectMerger(
            operation,
            new UserConflictResolver<ProjectReference>( operation, repositoryRootDirectory: rootFolder ),
            new ReferenceConflictResolver( new UserConflictResolver<Reference>( operation, notResolveOptionText: PackageNotInstalledText, repositoryRootDirectory: rootFolder ) ),
            new UserConflictResolver<RawItem>( operation, repositoryRootDirectory: rootFolder ),
            new UserDuplicateResolver<Reference>( operation, notResolveOptionText: PackageNotInstalledText, repositoryRootDirectory: rootFolder ) );

              foreach ( var conflict in conflictPaths.Where( p => p.EndsWith( ".csproj" ) || p.EndsWith( ".fsproj" ) || p.EndsWith( ".xproj" )) ) {

            var fullConflictPath = Path.Combine( folder.FullName, conflict );
            logger.Info( $"{LogHelper.Header}{Environment.NewLine}Examining concurrent modification for {fullConflictPath}" );

            var baseContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ancestor, conflict );
            var localContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ours, conflict );
            var incomingContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Theirs, conflict );

            var conflictFolder = Path.GetDirectoryName( Path.Combine( rootFolder, conflict ) );

            if ( conflictFolder == null ) {
              throw new Exception( "No conflict folder" );
            }

            if ( string.IsNullOrEmpty( localContent ) || string.IsNullOrEmpty( incomingContent ) ) {
              logger.Log( LogLevel.Info, $"Skipping '{conflict}' - no content on one side" );
              continue;
            }

            var localDocument = XDocument.Parse( localContent );
            var incomingDocument = XDocument.Parse( incomingContent );
            var baseDocument = XDocument.Parse( baseContent ?? "<?xml version=\"1.0\" encoding=\"utf - 8\"?><Project/>" );

            var resolved = false;

            try {
              var projectFolder = Path.Combine( folder.FullName, conflictFolder );

              var packagesConfigFilePath = ProjectPackages.GetPackagesConfigFilePath( projectFolder );
              var packagesConfig = ProjectPackages.TryLoadPackagesConfig( packagesConfigFilePath );
              if ( packagesConfig == null ) {
            continue;
              }

              var packageIndex = new ProjectPackages( projectFolder, NuGetExtensions.FindRelativePathOfPackagesFolder( projectFolder ), packagesConfig );

              Item[] items = merger.Merge(
              conflict,
              packageIndex,
              baseDocument,
              localDocument,
              incomingDocument ).ToArray();

              // Now remove everything we have handled, to check if we are done.
              ProjectFile.DeleteItems( localDocument );
              ProjectFile.DeleteItems( incomingDocument );
              ProjectFile.DeleteItems( baseDocument );

              ProjectFile.AddItems( baseDocument, items );
              ProjectFile.AddItems( localDocument, items );
              ProjectFile.AddItems( incomingDocument, items );

              XDocument resolvedDocument = null;

              var localXml = localDocument.ToString();
              var incomingXml = incomingDocument.ToString();
              var baseXml = baseDocument.ToString();

              // Check for any project file changes outside of the references and items.
              if ( localXml == incomingXml ) {
            resolvedDocument = localDocument;
              } else if ( baseXml == localXml ) {
            resolvedDocument = incomingDocument;
              } else if ( baseXml == incomingXml ) {
            resolvedDocument = localDocument;
              }

              if ( resolvedDocument != null ) {
            // We handled all the differences
            using ( var textWriter = new StreamWriter( fullConflictPath ) ) {
              SerialisationHelper.WriteXml( resolvedDocument, textWriter );
            }
            using ( var repository = new Repository( rootFolder ) ) {
              repository.Stage( conflict );
            }

            resolved = true;
              }
            }       catch ( MergeAbortException ) {
              logger.Log( LogLevel.Info, $"Project merge aborted for {conflict}" );
              continue;
            } catch ( UserQuitException ) {
              throw;
            } catch ( Exception exception ) {
              logger.Log( LogLevel.Error, exception, $"Project merge failed for {conflict}{Environment.NewLine}{exception}" );
//.........这里部分代码省略.........
开发者ID:configit-open-source,项目名称:csmerge,代码行数:101,代码来源:CsMerge.cs

示例12: ProcessPackagesConfig

        private static void ProcessPackagesConfig(
      CurrentOperation operation,
      string[] conflictPaths,
      DirectoryInfo folder,
      Logger logger,
      string rootFolder )
        {
            var packagesConfigMerger = new PackagesConfigMerger(
            operation,
            new UserConflictResolver<ConfigitPackageReference>( operation, repositoryRootDirectory: rootFolder ) );

              foreach ( var conflict in conflictPaths.Where( p => Path.GetFileName( p ) == "packages.config" ) ) {

            var fullConflictPath = Path.Combine( folder.FullName, conflict );
            logger.Info( $"{LogHelper.Header}{Environment.NewLine}Examining concurrent modification for {fullConflictPath}" );

            var baseContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ancestor, conflict );
            var localContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Ours, conflict );
            var incomingContent = GitHelper.GetConflictContent( rootFolder, StageLevel.Theirs, conflict );

            // TODO: Is this correct? if base is not null then we have a deletion of the packages config file
            if ( string.IsNullOrEmpty( localContent ) || string.IsNullOrEmpty( incomingContent ) ) {
              logger.Log( LogLevel.Info, $"Skipping '{conflict}' - no content on one side" );
              continue;
            }

            bool resolved = false;

            try {
              var result = packagesConfigMerger.Merge( conflict,
              baseContent == null ? new ConfigitPackageReference[0]:
                                   NuGetExtensions.ReadPackageReferences( baseContent ),
              NuGetExtensions.ReadPackageReferences( localContent ),
              NuGetExtensions.ReadPackageReferences( incomingContent ) ).ToArray();

              result.Write( fullConflictPath );

              using ( var repository = new Repository( rootFolder ) ) {
            repository.Stage( conflict );
            resolved = true;
              }

            } catch ( MergeAbortException ) {
              logger.Log( LogLevel.Info, $"Package merge aborted for {conflict}" );
              continue;
            }
            catch ( UserQuitException ) {
              throw;
            } catch ( Exception exception ) {
              logger.Log( LogLevel.Error, exception, $"Package merge failed for {conflict}{Environment.NewLine}{exception}" );
            }

            if ( resolved ) {
              continue;
            }

              string userQuestionText = $"Could not resolve conflict: {conflict}{Environment.NewLine}Would you like to resolve the conflict with the mergetool?";
              var userQuestion = new UserQuestion<bool>( userQuestionText, UserQuestion<bool>.YesNoOptions() );

            if ( !userQuestion.Resolve() ) {
              continue;
            }

            XDocument localDocument = XDocument.Parse( localContent );
            XDocument theirDocument = XDocument.Parse( incomingContent );
            XDocument baseDocument = baseContent == null ? new XDocument() : XDocument.Parse( baseContent );

            using ( var repository = new Repository( rootFolder ) ) {
              GitHelper.ResolveWithStandardMergetool(
                repository,
                fullConflictPath,
                baseDocument,
                localDocument,
                theirDocument,
                logger,
                conflict );
            }
              }
        }
开发者ID:configit-open-source,项目名称:csmerge,代码行数:79,代码来源:CsMerge.cs

示例13: WriteEntry

 private static void WriteEntry(Logger logger, JobLogEntry entry)
 {
     LogEventInfo evt = new LogEventInfo(
         entry.FullEvent.Level,
         entry.FullEvent.LoggerName,
         CultureInfo.CurrentCulture,
         entry.FullEvent.FormattedMessage,
         new object[0])
         {
             TimeStamp = entry.Timestamp.LocalDateTime
         };
     logger.Log(evt);
 }
开发者ID:henrycomein,项目名称:NuGetGallery,代码行数:13,代码来源:TailJobLogTask.cs

示例14: Main

        static void Main(string[] args)
        {
            ConfigureLogging(_verboseLogging);

            _logger = LogManager.GetCurrentClassLogger();

            var filePath = "";
            var connectionString = "";

            var showHelp = false;

            var p = new OptionSet
            {
                { "f|file=",    "The assembly which should be uploaded",    v => { if (v != null) filePath = v; } },
                { "c|connection=",  "The target for the upload",            v => { if (v != null) connectionString = v; } },
                { "v|verbose",  "Verbose log output",                       v => { if (v != null) _verboseLogging = true; } },
                { "h|help",     "show this message and exit",               v => showHelp = v != null },
            };

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                var name = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
                Console.Write("{0}: ", name);
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", name);
                return;
            }

            if (_verboseLogging)
            {
                ConfigureLogging(_verboseLogging);
            }

            if (showHelp)
            {
                ShowHelp(p);
                return;
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                _logger.Log(LogLevel.Error, () => "Missing filePath.");

                ShowHelp(p);
                Environment.Exit(1);
            }
            else
            {
                if (!File.Exists(filePath))
                {
                    _logger.Log(LogLevel.Error, () => string.Format("Could not find the specified file at {0}", filePath));
                    Environment.Exit(100);
                }
            }

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                _logger.Log(LogLevel.Error, () => "Missing connectionstring.");

                ShowHelp(p);
                Environment.Exit(2);
            }

            var assembly = Assembly.ReflectionOnlyLoadFrom(filePath); // TODO catch NotFound
            _logger.Log(LogLevel.Info, () => "Loaded assembly.");

            var con = CrmConnection.Parse(connectionString);
            var service = new OrganizationService(con);

            var pluginAssemblyId = FindPluginAssembly(service, assembly.GetName().Name);

            if (pluginAssemblyId != Guid.Empty)
            {
                UpdatePluginAssembly(service, pluginAssemblyId, filePath);
            }
            else
            {
                _logger.Log(LogLevel.Error, () => "Sorry, I am unable to find the appropriate assembly in the specified CRM organization. Is it already registered?");
                Environment.Exit(3);
            }
        }
开发者ID:skfd,项目名称:PluginAssemblyLoader,代码行数:85,代码来源:Program.cs

示例15: ErrorMessageWithLog

 public static void ErrorMessageWithLog(Window parent, string userMessage, Logger logger, Exception ex, LogLevel level = null)
 {
     if (level == null)
         level = LogLevel.Error;
     logger.Log (level, ex, userMessage);
     ErrorMessage (parent, ex, userMessage);
 }
开发者ID:QualitySolution,项目名称:QSProjects,代码行数:7,代码来源:QSMain.cs


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