Skip to content

Commit 6261d9d

Browse files
committed
add logging and cleanup base adapter
1 parent a440364 commit 6261d9d

14 files changed

Lines changed: 535 additions & 415 deletions

File tree

FileSystem.Adapters.AmazonS3/src/AmazonS3Adapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public override void Dispose()
3333

3434
public override void Connect()
3535
{
36+
Logger.LogStartConnectingAdapter(this);
37+
Logger.LogFinishedConnectingAdapter(this);
3638
}
3739

3840
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)

FileSystem.Adapters.AzureBlobStorage/src/AzureBlobStorageAdapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public override void Dispose()
3030

3131
public override void Connect()
3232
{
33+
Logger.LogStartConnectingAdapter(this);
34+
Logger.LogFinishedConnectingAdapter(this);
3335
}
3436

3537
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)

FileSystem.Adapters.AzureFileStorage/src/AzureFileStorageAdapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public override void Dispose()
2929

3030
public override void Connect()
3131
{
32+
Logger.LogStartConnectingAdapter(this);
33+
Logger.LogFinishedConnectingAdapter(this);
3234
}
3335

3436
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)

FileSystem.Adapters.Dropbox/src/DropboxAdapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public override void Dispose()
3131

3232
public override void Connect()
3333
{
34+
Logger.LogStartConnectingAdapter(this);
35+
Logger.LogFinishedConnectingAdapter(this);
3436
}
3537

3638
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)

FileSystem.Adapters.GoogleDrive/src/GoogleDriveAdapter.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Google;
99
using Google.Apis.Drive.v3;
1010
using Google.Apis.Drive.v3.Data;
11-
using Microsoft.Extensions.Logging;
1211
using SharpGrip.FileSystem.Cache;
1312
using SharpGrip.FileSystem.Exceptions;
1413
using SharpGrip.FileSystem.Extensions;
@@ -43,6 +42,8 @@ public override void Dispose()
4342

4443
public override void Connect()
4544
{
45+
Logger.LogStartConnectingAdapter(this);
46+
Logger.LogFinishedConnectingAdapter(this);
4647
}
4748

4849
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)
@@ -356,13 +357,8 @@ protected override Exception Exception(Exception exception)
356357

357358
private async Task<string> GetAbsolutePath(File file, CancellationToken cancellationToken = default)
358359
{
359-
Logger.LogDebug("Start resolving path for object '{Name}' with ID '{Id}'", file.Name, file.Id);
360-
361360
if (file.Parents == null || !file.Parents.Any())
362361
{
363-
Logger.LogTrace("No parents found for object '{Name}' with ID '{Id}'; returning absolute path '{Name}'", file.Name, file.Id, file.Name);
364-
Logger.LogDebug("Finished resolving path for object '{Name}' with ID '{Id}'; {Path}", file.Name, file.Id, string.Join("/", file.Name));
365-
366362
return file.Name;
367363
}
368364

@@ -371,29 +367,18 @@ private async Task<string> GetAbsolutePath(File file, CancellationToken cancella
371367
while (file.Parents != null && file.Parents.Any())
372368
{
373369
var parentId = file.Parents[0];
374-
375-
Logger.LogDebug("Retrieving parent object with ID '{ParentId}' for object '{Name}' with ID '{Id}'", parentId, file.Name, file.Id);
376-
377370
var cacheEntry = await GetOrCreateCacheEntryAsync(parentId, async () => new CacheEntry<string, File>(parentId, await RequestObjectById(parentId, cancellationToken)));
378371
var parent = cacheEntry.Value;
379372

380-
Logger.LogDebug("Finished retrieving parent object with ID '{ParentId}' for object '{Name}' with ID '{Id}'", parentId, file.Name, file.Id);
381-
382373
if (parent.Parents == null || !parent.Parents.Any())
383374
{
384-
Logger.LogTrace("No parents found for object '{Name}' with ID '{Id}'; aborting path resolving", parent.Name, parent.Id);
385-
386375
break;
387376
}
388377

389378
pathParts.Insert(0, parent.Name);
390379
file = parent;
391-
392-
Logger.LogDebug("Resolving path for object '{Name}' with ID '{Id}'; {Path}", file.Name, file.Id, string.Join("/", pathParts));
393380
}
394381

395-
Logger.LogDebug("Finished resolving path for object '{Name}' with ID '{Id}'; {Path}", file.Name, file.Id, string.Join("/", pathParts));
396-
397382
return string.Join("/", pathParts);
398383
}
399384

@@ -478,21 +463,10 @@ private async Task<File> RequestObjectById(string id, CancellationToken cancella
478463
{
479464
directoryList = await request.ExecuteAsync(cancellationToken);
480465

481-
Logger.LogWarning("Retrieving directories for path '{Path}' and last path part '{LastPathPart}'", path, GetLastPathPart(path));
482-
483-
foreach (var directory in directoryList.Files)
484-
{
485-
Logger.LogInformation("Found directory '{DirectoryId}' with path '{DirectoryPath}'; trashed: {Trashed}", directory.Id, directory.Name, directory.Trashed);
486-
}
487-
488-
Logger.LogWarning("Finished retrieving {DirectoryCount} directories for path '{Path}' and last path part '{LastPathPart}'", directoryList.Files.Count, path, GetLastPathPart(path));
489-
490466
foreach (var directory in directoryList.Files)
491467
{
492468
try
493469
{
494-
Logger.LogWarning("Start resolving absolute path for directory '{DirectoryId}' with path '{DirectoryPath}'", directory.Id, directory.Name);
495-
496470
var directoryPath = (await GetAbsolutePath(directory, cancellationToken)).EnsureTrailingForwardSlash();
497471

498472
TryAddCacheEntry(new CacheEntry<string, File>(directory.Id, directory));

FileSystem.Adapters.MicrosoftOneDrive/src/MicrosoftOneDriveAdapter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Microsoft.Graph;
88
using SharpGrip.FileSystem.Exceptions;
9+
using SharpGrip.FileSystem.Extensions;
910
using SharpGrip.FileSystem.Models;
1011
using DirectoryNotFoundException = SharpGrip.FileSystem.Exceptions.DirectoryNotFoundException;
1112
using FileNotFoundException = SharpGrip.FileSystem.Exceptions.FileNotFoundException;
@@ -30,6 +31,8 @@ public override void Dispose()
3031

3132
public override void Connect()
3233
{
34+
Logger.LogStartConnectingAdapter(this);
35+
Logger.LogFinishedConnectingAdapter(this);
3336
}
3437

3538
public override async Task<IFile> GetFileAsync(string virtualPath, CancellationToken cancellationToken = default)

FileSystem.Adapters.Sftp/src/SftpAdapter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Renci.SshNet.Common;
1111
using SharpGrip.FileSystem.Constants;
1212
using SharpGrip.FileSystem.Exceptions;
13+
using SharpGrip.FileSystem.Extensions;
1314
using SharpGrip.FileSystem.Models;
1415
using SharpGrip.FileSystem.Utilities;
1516
using DirectoryNotFoundException = SharpGrip.FileSystem.Exceptions.DirectoryNotFoundException;
@@ -43,7 +44,9 @@ public override void Connect()
4344

4445
try
4546
{
47+
Logger.LogStartConnectingAdapter(this);
4648
client.Connect();
49+
Logger.LogFinishedConnectingAdapter(this);
4750
}
4851
catch (Exception exception)
4952
{

0 commit comments

Comments
 (0)