public bool ShouldLog(LogAttribute logAttribute)
{
if (!ConfigFileSource.IsEnabled) return false;
ICollection<TagElement> tags = ConfigFileSource.Tags.OfType<TagElement>().ToList();
List<string> includedTags =
tags.Where(element => element.IncludeTag).Select(element => element.Name).ToList();
List<string> excludedTags =
tags.Where(element => element.ExcludeTag).Select(element => element.Name).ToList();
if (includedTags.Any(tag => logAttribute.CurrentMethodFullName.StartsWith(tag, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
if (excludedTags.Any(tag => logAttribute.CurrentMethodFullName.StartsWith(tag, StringComparison.OrdinalIgnoreCase)))
{
return false;
}
if (!string.IsNullOrWhiteSpace(logAttribute.Tags))
{
ICollection<string> currentTags = logAttribute.Tags.Split(_separators, StringSplitOptions.RemoveEmptyEntries).Select(tag => tag.Trim()).ToList();
if (currentTags.Any(currentTag => includedTags.Any(includedTag => currentTag.Equals(includedTag, StringComparison.OrdinalIgnoreCase))))
{
return true;
}
if (currentTags.Any(currentTag => excludedTags.Any(excludedTag => currentTag.Equals(excludedTag, StringComparison.OrdinalIgnoreCase))))
{
return false;
}
}
return true;
}