本文整理汇总了C#中ILog.LogError方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.LogError方法的具体用法?C# ILog.LogError怎么用?C# ILog.LogError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILog
的用法示例。
在下文中一共展示了ILog.LogError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}