public async static Task <bool> Log( string storageAccountName, string storageAccountKey, string contactTableName, string name, string email, string phone, string department, string message, string result, ILogger logger = null) { DateTime dt = DateTime.UtcNow; try { StorageCredentials storageCredentials = new StorageCredentials(storageAccountName, storageAccountKey); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 10); CloudTable table_Contact = tableClient.GetTableReference(contactTableName); await table_Contact.CreateIfNotExistsAsync(); ContactLog entity = new ContactLog((DateTime.MaxValue - dt).ToString()); entity.DT = dt; entity.MachineName = Environment.MachineName; entity.Application = Assembly.GetEntryAssembly().GetName().Name; entity.Name = name; entity.Email = email; entity.Phone = phone; entity.Department = department; entity.Message = message; entity.Result = result; TableResult operationResult = await table_Contact.ExecuteAsync(TableOperation.Insert(entity)); if (operationResult.HttpStatusCode != 204 && logger != null) { logger.Error(operationResult.HttpStatusCode.ToString() + " " + operationResult.Result.ToString()); } return(operationResult.HttpStatusCode == 204 ? true : false); } catch (Exception ex) { if (logger != null) { logger.Error(ex.ToString()); } Console.WriteLine(dt.ToString() + " " + Environment.MachineName + ":" + Assembly.GetEntryAssembly().GetName().Name + ": " + ex.ToString()); return(false); } }
public async static Task<bool> Log( string storageAccountName, string storageAccountKey, string contactTableName, string name, string email, string phone, string department, string message, string result, ILogger logger = null) { DateTime dt = DateTime.UtcNow; try { StorageCredentials storageCredentials = new StorageCredentials(storageAccountName, storageAccountKey); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 10); CloudTable table_Contact = tableClient.GetTableReference(contactTableName); await table_Contact.CreateIfNotExistsAsync(); ContactLog entity = new ContactLog((DateTime.MaxValue - dt).ToString()); entity.DT = dt; entity.MachineName = Environment.MachineName; entity.Application = Assembly.GetEntryAssembly().GetName().Name; entity.Name = name; entity.Email = email; entity.Phone = phone; entity.Department = department; entity.Message = message; entity.Result = result; TableResult operationResult = await table_Contact.ExecuteAsync(TableOperation.Insert(entity)); if (operationResult.HttpStatusCode != 204 && logger != null) { logger.Error(operationResult.HttpStatusCode.ToString() + " " + operationResult.Result.ToString()); } return operationResult.HttpStatusCode == 204 ? true : false; } catch (Exception ex) { if (logger != null) { logger.Error(ex.ToString()); } Console.WriteLine(dt.ToString() + " " + Environment.MachineName + ":" + Assembly.GetEntryAssembly().GetName().Name + ": " + ex.ToString()); return false; } }