/// <summary> /// Attempts to retrieve a blob path out of log entry's RequestedObjectKey. /// </summary> /// <returns> /// A valid instance of <see cref="BlobPath"/>, or null if log entry is not associated with a blob. /// </returns> public BlobPath ToBlobPath() { if (!ServiceType.HasValue || ServiceType != StorageServiceType.Blob) { return(null); } string path; Uri keyAsUri = new Uri(RequestedObjectKey, UriKind.RelativeOrAbsolute); if (keyAsUri.IsAbsoluteUri) { // assuming key is "https://storagesample.blob.core.windows.net/sample-container/sample-blob.txt" path = keyAsUri.Segments.Length > 1 ? keyAsUri.LocalPath.Substring(1) : String.Empty; } else { // assuming key is "/account/container/blob" int startPos = RequestedObjectKey.Length > 1 ? RequestedObjectKey.IndexOf('/', 1) : -1; path = startPos != -1 ? RequestedObjectKey.Substring(startPos + 1) : String.Empty; } if (String.IsNullOrEmpty(path)) { return(null); } BlobPath blobPath; if (!BlobPath.TryParse(path, false, out blobPath)) { return(null); } return(blobPath); }