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


C# ILog.LogMessage方法代码示例

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


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

示例1: ExamineAssets

        public static void ExamineAssets(ILog logger, string assetType, string package, string target, IEnumerable<string> items, out bool hasRealAsset, out bool hasPlaceHolder)
        {
            hasPlaceHolder = false;
            hasRealAsset = false;
            StringBuilder assetLog = new StringBuilder($"{assetType} assets for {package} on {target}: ");
            if (items != null && items.Any())
            {
                foreach (var runtimeItem in items)
                {
                    assetLog.AppendLine();
                    assetLog.Append($"  {runtimeItem}");

                    if (!hasRealAsset && NuGetAssetResolver.IsPlaceholder(runtimeItem))
                    {
                        hasPlaceHolder = true;
                    }
                    else
                    {
                        hasRealAsset = true;
                        hasPlaceHolder = false;
                    }
                }
            }
            else
            {
                assetLog.AppendLine();
                assetLog.Append("  <none>");
            }
            logger.LogMessage(LogImportance.Low, assetLog.ToString());
        }
开发者ID:ChadNedzlek,项目名称:buildtools,代码行数:30,代码来源:NuGetAssetResolver.cs

示例2: DetermineGenerationFromFile

        public Version DetermineGenerationFromFile(string assemblyPath, ILog log, Version expectedVersion = null, IDictionary<string, string> candidateRefs = null, ICollection<string> ignoredRefs = null)
        {
            Version maxGeneration = null;

            if (_generationCache.TryGetValue(assemblyPath, out maxGeneration))
            {
                log.LogMessage(LogImportance.Low, $"Generation of {assemblyPath} is dotnet{maxGeneration} from cache.");
                return maxGeneration;
            }

            string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
            if (ignoredRefs != null && ignoredRefs.Contains(assemblyName))
            {
                return null;
            }

            using (PEReader peReader = new PEReader(new FileStream(assemblyPath, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read)))
            {
                MetadataReader reader = peReader.GetMetadataReader();
                AssemblyDefinition assemblyDef = reader.GetAssemblyDefinition();

                assemblyName = reader.GetString(assemblyDef.Name);
                if (ignoredRefs != null && ignoredRefs.Contains(assemblyName))
                {
                    return null;
                }

                // break a circular dependency
                int cycleIndex = _cycleStack.IndexOf(assemblyName);
                if (cycleIndex != -1)
                {
                    log.LogError($"Cycle detected {string.Join(" > ", _cycleStack.Skip(cycleIndex).ToArray())} > {assemblyName}");
                    return null;
                }

                _cycleStack.Add(assemblyName);

                if (expectedVersion != null && !VersionUtility.IsCompatibleApiVersion(expectedVersion, assemblyDef.Version))
                {
                    log.LogError($"Expected version {expectedVersion} for referenced assembly {assemblyPath} but found {assemblyDef.Version}");
                }

                // first determine if the identity itself has a generation.
                maxGeneration = DetermineGenerationFromSeeds(assemblyName, assemblyDef.Version, log);

                foreach (var handle in reader.AssemblyReferences)
                {
                    AssemblyReference reference = reader.GetAssemblyReference(handle);
                    string referenceName = reader.GetString(reference.Name);

                    if (ignoredRefs != null && ignoredRefs.Contains(referenceName))
                    {
                        continue;
                    }

                    // indirect dependency: prefer the seed value if it exists since we only care about
                    // reference assembly generation for indirect dependencies
                    Version assemblyGeneration = DetermineGenerationFromSeeds(referenceName, reference.Version, log);

                    if (assemblyGeneration == null)
                    {
                        string contractPath = null;
                        if (candidateRefs != null && candidateRefs.TryGetValue(referenceName, out contractPath) &&
                            File.Exists(contractPath))
                        {
                            // traverse the indirect dependencies recursively.
                            assemblyGeneration = DetermineGenerationFromFile(contractPath, log, reference.Version, candidateRefs);
                        }
                        else
                        {
                            log.LogError($"Cannot resolve indirect dependency {referenceName}, Version={reference.Version}");
                        }
                    }

                    if (assemblyGeneration == null)
                    {
                        log.LogError($"Could not determine generation for {referenceName}, {reference.Version}.  File did not exist and isn't a known mapping.");
                    }

                    if (maxGeneration == null)
                    {
                        maxGeneration = assemblyGeneration;
                    }
                    else if (assemblyGeneration != null && assemblyGeneration > maxGeneration)
                    {
                        maxGeneration = assemblyGeneration;
                    }
                }
            }

            log.LogMessage(LogImportance.Low, $"Generation of {assemblyPath} is dotnet{maxGeneration}.");
            _generationCache.Add(assemblyPath, maxGeneration);
            _cycleStack.RemoveAt(_cycleStack.Count - 1);

            return maxGeneration;
        }
开发者ID:TerabyteX,项目名称:buildtools,代码行数:96,代码来源:Generations.cs

示例3: TryAndRepeat

 /// <summary>
 /// Executes the action. If it throws an exception it is repeated until repetition-count is reached.
 /// If repetitions is -1, it is repeated infinitely.
 /// </summary>
 public static void TryAndRepeat(Action action, int repetitions, string errorMessage, ILog log = null) {
   while (true) {
     try { action(); return; }
     catch (Exception e) {
       if (repetitions == 0) throw new HiveException(errorMessage, e);
       if (log != null) log.LogMessage(string.Format("{0}: {1} - will try again!", errorMessage, e.ToString()));
       repetitions--;
     }
   }
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:14,代码来源:HiveClient.cs

示例4: DetermineGenerationFromSeeds

        public Version DetermineGenerationFromSeeds(string assemblyName, Version assemblyVersion, ILog log)
        {
            // find the lowest generation that supports this assembly version
            Version result = null;
            Generation lowerGeneration = null, upperGeneration = null;

            foreach (var generation in _generations)
            {
                Version currentGenerationAssemblyVersion = null;
                if (generation.Assemblies.TryGetValue(assemblyName, out currentGenerationAssemblyVersion))
                {
                    if (assemblyVersion < currentGenerationAssemblyVersion)
                    {
                        // this generation supports a higher version of the target assembly
                        // last matching generation is the correct one
                        upperGeneration = generation;
                        break;
                    }

                    // this generation supports at least the target assembly
                    lowerGeneration = generation;
                    result = generation.Version;
                }
            }

            if (lowerGeneration == null && upperGeneration == null)
            {
                log.LogMessage(LogImportance.Low, "Assembly {0} is not tracked by generations.", assemblyName);
            }
            else if (lowerGeneration == null && upperGeneration != null)
            {
                log.LogError("Could not determine generation of assembly {0}.  It is lower than the lowest version of the contract supported by any generation.  {1} <= {2}(dotnet{3}).", assemblyName, assemblyVersion, upperGeneration.Assemblies[assemblyName], upperGeneration.Version);
            }
            else if (lowerGeneration != null && upperGeneration == null)
            {
                log.LogMessage(LogImportance.Low, "Assembly {0}, {1} is supported by dotnet{2}. {3}(dotnet{2}) <= {1}", assemblyName, assemblyVersion, lowerGeneration.Version, lowerGeneration.Assemblies[assemblyName]);
            }
            else
            {
                log.LogMessage(LogImportance.Low, "Assembly {0}, {1} is supported by dotnet{2}. {3}(dotnet{2}) <= {1} < {4}(dotnet{5})", assemblyName, assemblyVersion, lowerGeneration.Version, lowerGeneration.Assemblies[assemblyName], upperGeneration.Assemblies[assemblyName], upperGeneration.Version);
            }

            return result;
        }
开发者ID:TerabyteX,项目名称:buildtools,代码行数:44,代码来源:Generations.cs

示例5: UploadTaskWithChildren

    /// <summary>
    /// Uploads the given task and all its child-jobs while setting the proper parentJobId values for the childs
    /// </summary>
    /// <param name="parentHiveTask">shall be null if its the root task</param>
    private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, CancellationToken cancellationToken) {
      taskUploadSemaphore.WaitOne();
      bool semaphoreReleased = false;
      try {
        cancellationToken.ThrowIfCancellationRequested();
        lock (jobCountLocker) {
          taskCount[0]++;
        }
        TaskData taskData;
        List<IPluginDescription> plugins;

        if (hiveTask.ItemTask.ComputeInParallel) {
          hiveTask.Task.IsParentTask = true;
          hiveTask.Task.FinishWhenChildJobsFinished = true;
          taskData = hiveTask.GetAsTaskData(true, out plugins);
        } else {
          hiveTask.Task.IsParentTask = false;
          hiveTask.Task.FinishWhenChildJobsFinished = false;
          taskData = hiveTask.GetAsTaskData(false, out plugins);
        }
        cancellationToken.ThrowIfCancellationRequested();

        TryAndRepeat(() => {
          if (!cancellationToken.IsCancellationRequested) {
            lock (pluginLocker) {
              HiveServiceLocator.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));
            }
          }
        }, Settings.Default.MaxRepeatServiceCalls, "Failed to upload plugins");
        cancellationToken.ThrowIfCancellationRequested();
        hiveTask.Task.PluginsNeededIds.Add(configPluginId);
        hiveTask.Task.JobId = jobId;

        log.LogMessage(string.Format("Uploading task ({0} kb, {1} objects)", taskData.Data.Count() / 1024, hiveTask.ItemTask.GetObjectGraphObjects().Count()));
        TryAndRepeat(() => {
          if (!cancellationToken.IsCancellationRequested) {
            if (parentHiveTask != null) {
              hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData));
            } else {
              hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList()));
            }
          }
        }, Settings.Default.MaxRepeatServiceCalls, "Failed to add task", log);
        cancellationToken.ThrowIfCancellationRequested();

        lock (jobCountLocker) {
          progress.ProgressValue = (double)taskCount[0] / totalJobCount;
          progress.Status = string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount);
        }

        var tasks = new List<TS.Task>();
        foreach (HiveTask child in hiveTask.ChildHiveTasks) {
          var task = TS.Task.Factory.StartNew((tuple) => {
            var arguments = (Tuple<HiveTask, HiveTask>)tuple;
            UploadTaskWithChildren(progress, arguments.Item1, arguments.Item2, groups, taskCount, totalJobCount, configPluginId, jobId, log, cancellationToken);
          }, new Tuple<HiveTask, HiveTask>(child, hiveTask));
          task.ContinueWith((x) => log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
          tasks.Add(task);
        }
        taskUploadSemaphore.Release(); semaphoreReleased = true; // the semaphore has to be release before waitall!
        TS.Task.WaitAll(tasks.ToArray());
      }
      finally {
        if (!semaphoreReleased) taskUploadSemaphore.Release();
      }
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:70,代码来源:HiveClient.cs


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