Azure provides Pay as you go service, so it is important to use the services efficiently. Pricing of table storage is higher than blob storage, so it is good idea to archive your logs to the blob storage. Diagnostic enabled for Azure cloud service configuration.
We and retrieve record from both the tables ( WadLogsTable, WADWindowsEventLogTable).
-
-
-
-
-
-
-
-
-
- private List<T> GetLogFromTable<T>(string environment, long startTick, long endTick)
- where T : TableEntity, new()
- {
-
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[environment].ToString());
-
-
- CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
-
-
- CloudTable table = tableClient.GetTableReference(typeof(T).Name);
-
-
- if (table.Exists())
- {
-
-
- TableQuery<T> q = new TableQuery<T>().Where(
- TableQuery.CombineFilters(
- TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "0" + startTick),
- TableOperators.And,
- TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, "0" + end Tick)));
-
-
- return table.ExecuteQuery<T>(q).ToList<T>();
- }
- return null;
- }
-
-
-
-
-
-
-
-
-
-
- private byte[] ConvertTableToBytes<T>( IList<T> list, string fileName)
- where T : TableEntity, new()
- {
-
- StringBuilder headerText = new StringBuilder();
- StringBuilder contentText = new StringBuilder();
- List<PropertyInfo> listOfProperties = new List<PropertyInfo>();
- string delemiter = "\t";
- string filetype = "txt";
-
-
- foreach (var prop in typeof(T).GetProperties())
- {
- listOfProperties.Add(prop);
- headerText.AppendFormat("{0}{1}", prop.Name, delemiter);
- }
-
- StringBuilder logText = new StringBuilder();
-
-
- logText.AppendLine(headerText.ToString());
-
-
- foreach (T item in list)
- {
- contentText.Clear();
- foreach (var prop in listOfProperties)
- {
- contentText.AppendFormat("{0}{1}", prop.GetValue(item), delemiter);
- }
- logText.AppendLine(contentText.ToString());
- }
-
-
- File.WriteAllText("_" + fileName + "." + filetype, logText.ToString(), Encoding.Unicode);
- byte[] result = File.ReadAllBytes("_" + fileName + "." + filetype);
- return result;
- }
-
-
-
-
-
-
-
-
-
-
- private string UploadToBlob(string environment, string Container, string fileName, byte[] file)
- {
-
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[environment].ToString());
-
-
- CloudBlobClient blogClient = storageAccount.CreateCloudBlobClient();
-
-
- CloudBlobContainer container = blogClient.GetContainerReference(Container.ToLower());
-
-
- container.CreateIfNotExists();
-
-
- CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
-
-
- using (var memoryStream = new System.IO.MemoryStream(file))
- {
- blockBlob.UploadFromStream(memoryStream);
- }
-
-
- return blockBlob.Uri.ToString();
- }
-
-
-
-
-
-
-
-
-
-
-
- private bool DeleteBulkDataFromAzureTable<T>(string environment, long startTick, long endTick, IList<T> list)
- where T : TableEntity, new()
- {
-
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[environment].ToString());
-
-
- CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
-
-
- CloudTable table = tableClient.GetTableReference(typeof(T).Name);
-
-
- if (table.Exists())
- {
-
- foreach (var item in list)
- {
-
-
- if (item != null)
- {
- TableOperation deleteOperation = TableOperation.Delete(item);
-
-
- table.Execute(deleteOperation);
- }
- }
- return true;
- }
- return false;
- }