Skip to content

Commit 393cc06

Browse files
committed
Added debug logging to AzureFileSystem methods to help with diagnosing issues
1 parent 6a974db commit 393cc06

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ public static AzureFileSystem GetInstance(string containerName, string rootUrl,
263263
/// <param name="overrideIfExists">Whether to override the file if it already exists.</param>
264264
public void AddFile(string path, Stream stream, bool overrideIfExists)
265265
{
266+
Current.Logger.Debug<AzureBlobFileSystem>($"AddFile(path, steam, overrideIfExists) method executed with path:{path}");
267+
266268
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
267269

268270
if (blockBlob != null)
@@ -333,6 +335,8 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
333335
/// <param name="stream">The <see cref="Stream"/> containing the file contents.</param>
334336
public void AddFile(string path, Stream stream)
335337
{
338+
Current.Logger.Debug<AzureBlobFileSystem>($"AddFile(path, steam) method executed with path:{path}");
339+
336340
this.AddFile(path, stream, true);
337341
}
338342

@@ -353,6 +357,8 @@ public void AddFile(string path, string physicalPath, bool overrideIfExists = tr
353357
/// </param>
354358
public void DeleteDirectory(string path, bool recursive)
355359
{
360+
Current.Logger.Debug<AzureBlobFileSystem>($"DeleteDirectory(path, recursive) method executed with path:{path}");
361+
356362
path = this.FixPath(path);
357363

358364
if (!this.DirectoryExists(path))
@@ -406,6 +412,8 @@ public void DeleteDirectory(string path, bool recursive)
406412
/// <param name="path">The name of the directory to remove.</param>
407413
public void DeleteDirectory(string path)
408414
{
415+
Current.Logger.Debug<AzureBlobFileSystem>($"DeleteDirectory(path) method executed with path:{path}");
416+
409417
this.DeleteDirectory(path, false);
410418
}
411419

@@ -415,6 +423,8 @@ public void DeleteDirectory(string path)
415423
/// <param name="path">The name of the file to remove.</param>
416424
public void DeleteFile(string path)
417425
{
426+
Current.Logger.Debug<AzureBlobFileSystem>($"DeleteFile(path) method executed with path:{path}");
427+
418428
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
419429

420430
if (blockBlob != null)
@@ -439,6 +449,8 @@ public void DeleteFile(string path)
439449
/// </returns>
440450
public bool DirectoryExists(string path)
441451
{
452+
Current.Logger.Debug<AzureBlobFileSystem>($"DirectoryExists(path) method executed with path:{path}");
453+
442454
string fixedPath = this.FixPath(path);
443455
CloudBlobDirectory directory = this.cloudBlobContainer.GetDirectoryReference(fixedPath);
444456

@@ -454,6 +466,8 @@ public bool DirectoryExists(string path)
454466
/// </returns>
455467
public bool FileExists(string path)
456468
{
469+
Current.Logger.Debug<AzureBlobFileSystem>($"FileExists(path) method executed with path:{path}");
470+
457471
CloudBlockBlob blockBlobReference = this.GetBlockBlobReference(path);
458472
return blockBlobReference?.Exists() ?? false;
459473
}
@@ -467,6 +481,8 @@ public bool FileExists(string path)
467481
/// </returns>
468482
public DateTimeOffset GetCreated(string path)
469483
{
484+
Current.Logger.Debug<AzureBlobFileSystem>($"GetCreated(path) method executed with path:{path}");
485+
470486
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
471487

472488
if (blockBlob != null)
@@ -492,6 +508,8 @@ public DateTimeOffset GetCreated(string path)
492508
/// </returns>
493509
public IEnumerable<string> GetDirectories(string path)
494510
{
511+
Current.Logger.Debug<AzureBlobFileSystem>($"GetDirectories(path) method executed with path:{path}");
512+
495513
CloudBlobDirectory directory = this.GetDirectoryReference(path);
496514

497515
IEnumerable<IListBlobItem> blobs = directory.ListBlobs().Where(blob => blob is CloudBlobDirectory).ToList();
@@ -510,6 +528,8 @@ public IEnumerable<string> GetDirectories(string path)
510528
/// </returns>
511529
public IEnumerable<string> GetFiles(string path, string filter)
512530
{
531+
Current.Logger.Debug<AzureBlobFileSystem>($"GetFiles(path, filter) method executed with path:{path} & filter {filter}");
532+
513533
IEnumerable<IListBlobItem> blobs = this.cloudBlobContainer.ListBlobs(this.FixPath(path), true);
514534

515535
var blobList = blobs as IList<IListBlobItem> ?? blobs.ToList();
@@ -550,6 +570,8 @@ public IEnumerable<string> GetFiles(string path, string filter)
550570
/// </returns>
551571
public IEnumerable<string> GetFiles(string path)
552572
{
573+
Current.Logger.Debug<AzureBlobFileSystem>($"GetFiles(path) method executed with path:{path}");
574+
553575
return this.GetFiles(path, "*.*");
554576
}
555577

@@ -562,6 +584,8 @@ public IEnumerable<string> GetFiles(string path)
562584
/// </returns>
563585
public string GetFullPath(string path)
564586
{
587+
Current.Logger.Debug<AzureBlobFileSystem>($"GetFullPath(path) method executed with path:{path}");
588+
565589
return this.ResolveUrl(path, false);
566590
}
567591

@@ -574,6 +598,8 @@ public string GetFullPath(string path)
574598
/// </returns>
575599
public DateTimeOffset GetLastModified(string path)
576600
{
601+
Current.Logger.Debug<AzureBlobFileSystem>($"GetLastModified(path) method executed with path:{path}");
602+
577603
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
578604

579605
if (blockBlob != null)
@@ -594,6 +620,8 @@ public DateTimeOffset GetLastModified(string path)
594620
/// </returns>
595621
public string GetRelativePath(string fullPathOrUrl)
596622
{
623+
Current.Logger.Debug<AzureBlobFileSystem>($"GetRelativePath(path) method executed with fullPathOrUrl:{fullPathOrUrl}");
624+
597625
return this.FixPath(fullPathOrUrl);
598626
}
599627

@@ -607,6 +635,8 @@ public string GetRelativePath(string fullPathOrUrl)
607635
/// </returns>
608636
public string GetUrl(string path)
609637
{
638+
Current.Logger.Debug<AzureBlobFileSystem>($"GetUrl(path) method executed with path:{path}");
639+
610640
if (this.DisableVirtualPathProvider)
611641
{
612642
return this.ResolveUrl(path, false);
@@ -618,6 +648,8 @@ public string GetUrl(string path)
618648
/// <inheritdoc/>
619649
public long GetSize(string path)
620650
{
651+
Current.Logger.Debug<AzureBlobFileSystem>($"GetSize(path) method executed with path:{path}");
652+
621653
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
622654

623655
if (blockBlob != null)
@@ -637,6 +669,8 @@ public long GetSize(string path)
637669
/// </returns>
638670
public Stream OpenFile(string path)
639671
{
672+
Current.Logger.Debug<AzureBlobFileSystem>($"OpenFile(path) method executed with path:{path}");
673+
640674
CloudBlockBlob blockBlob = this.GetBlockBlobReference(path);
641675

642676
if (blockBlob != null)
@@ -670,6 +704,8 @@ public Stream OpenFile(string path)
670704
/// <returns>The <see cref="CloudBlobContainer"/></returns>
671705
public static CloudBlobContainer CreateContainer(CloudBlobClient cloudBlobClient, string containerName, BlobContainerPublicAccessType accessType)
672706
{
707+
Current.Logger.Debug<AzureBlobFileSystem>($"CreateContainer(cloudBlobClient, containerName, accessType) method executed with containerName:{containerName}");
708+
673709
containerName = containerName.ToLowerInvariant();
674710

675711
// Validate container name - from: http://stackoverflow.com/a/23364534/5018
@@ -743,6 +779,8 @@ public static CloudBlobContainer CreateContainer(CloudBlobClient cloudBlobClient
743779
/// </returns>
744780
private CloudBlockBlob GetBlockBlobReference(string path)
745781
{
782+
Current.Logger.Debug<AzureBlobFileSystem>($"GetBlockBlobReference(path) method executed with path:{path}");
783+
746784
string blobPath = this.FixPath(path);
747785

748786
// Only make the request if there is an actual path. See issue 8.
@@ -761,6 +799,8 @@ private CloudBlockBlob GetBlockBlobReference(string path)
761799
/// </returns>
762800
private CloudBlobDirectory GetDirectoryReference(string path)
763801
{
802+
Current.Logger.Debug<AzureBlobFileSystem>($"GetDirectoryReference(path) method executed with path:{path}");
803+
764804
string blobPath = this.FixPath(path);
765805
return this.cloudBlobContainer.GetDirectoryReference(blobPath);
766806
}
@@ -775,6 +815,8 @@ private CloudBlobDirectory GetDirectoryReference(string path)
775815
/// </returns>
776816
private string ResolveUrl(string path, bool relative)
777817
{
818+
Current.Logger.Debug<AzureBlobFileSystem>($"ResolveUrl(path) method executed with path:{path}");
819+
778820
// First create the full url
779821
string fixedPath = this.FixPath(path);
780822

0 commit comments

Comments
 (0)