Add NTFS data area diagnostics logging

This commit is contained in:
Meik
2026-06-16 14:47:21 +02:00
parent f1fb5dbc1b
commit 275abe8ebd
2 changed files with 283 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ namespace LiamNtfs
public PrincipalContext adContext = null;
public Exception LastException { get; private set; } = null;
public string LastErrorMessage { get; private set; } = null;
public cNtfsEnumerationDiagnostics LastEnumerationDiagnostics { get; private set; } = new cNtfsEnumerationDiagnostics();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ResetError()
@@ -169,6 +170,7 @@ namespace LiamNtfs
public async Task<cNtfsCollectionBase> RequestFoldersListAsync(string rootPath, int depth)
{
ResetError();
LastEnumerationDiagnostics = new cNtfsEnumerationDiagnostics(rootPath, depth);
try
{
await Task.Delay(0);
@@ -217,7 +219,9 @@ namespace LiamNtfs
}
catch (Exception E)
{
cLogManager.LogEntry($"Could not enumerate directories under '{rootPath.FullName}': {E.Message}", LogLevels.Warning);
LastEnumerationDiagnostics.EnumerationFailures++;
LastEnumerationDiagnostics.AddFailure(rootPath.FullName, E);
cLogManager.LogEntry($"NTFS enumeration failed under '{rootPath.FullName}'. ReturnedPartialResult=true. Error='{E.Message}'", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
return folders;
}
@@ -239,11 +243,14 @@ namespace LiamNtfs
}
catch (Exception E)
{
cLogManager.LogEntry($"Could not read directory metadata for '{directory.FullName}': {E.Message}", LogLevels.Warning);
LastEnumerationDiagnostics.MetadataFailures++;
LastEnumerationDiagnostics.AddFailure(directory.FullName, E);
cLogManager.LogEntry($"NTFS directory metadata read failed for '{directory.FullName}'. DirectorySkipped=true. Error='{E.Message}'", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
continue;
}
LastEnumerationDiagnostics.FoldersEnumerated++;
folders.Add(folder);
if (depth <= 0)
continue;
@@ -256,7 +263,9 @@ namespace LiamNtfs
}
catch (Exception E)
{
cLogManager.LogEntry($"Could not scan subtree '{directory.FullName}': {E.Message}", LogLevels.Warning);
LastEnumerationDiagnostics.SubtreeFailures++;
LastEnumerationDiagnostics.AddFailure(directory.FullName, E);
cLogManager.LogEntry($"NTFS subtree scan failed for '{directory.FullName}'. ReturnedPartialResult=true. Error='{E.Message}'", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
}
}
@@ -330,6 +339,39 @@ namespace LiamNtfs
}
}
public class cNtfsEnumerationDiagnostics
{
private const int MaxSamples = 10;
public cNtfsEnumerationDiagnostics()
{
}
public cNtfsEnumerationDiagnostics(string rootPath, int depth)
{
RootPath = rootPath ?? string.Empty;
Depth = depth;
}
public string RootPath { get; private set; } = string.Empty;
public int Depth { get; private set; }
public int FoldersEnumerated { get; set; }
public int EnumerationFailures { get; set; }
public int MetadataFailures { get; set; }
public int SubtreeFailures { get; set; }
public List<string> FailureSamples { get; } = new List<string>();
public int TotalFailures => EnumerationFailures + MetadataFailures + SubtreeFailures;
public void AddFailure(string path, Exception exception)
{
if (FailureSamples.Count >= MaxSamples)
return;
FailureSamples.Add($"{path}: {exception?.GetType().Name}: {exception?.Message}");
}
}
public class cNtfsLogonInfo
{