/** * @brief Save log task processor. \n */ public static bool RunLog(CBLoggers message) { if (globalVal.CloudBreadLoggerSetting != "") { if (string.IsNullOrEmpty(message.memberID)) { message.memberID = ""; /// in case of non-member triggered job } /// critical error case, save in ATS CloudBreadErrorLog if (message.Level.ToUpper() == "ERROR") { try { /// Save error log on Azure Table Storage { /// Azure Table Storage connection retry policy var tableStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); CloudStorageAccount storageAccountT = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountT.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy; CloudTable table = tableClient.GetTableReference("CloudBreadErrorLog"); CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); } } catch (Exception) { /// Catch fail to log on database. Most case database connection or login fail issue. throw; } } else { /// Regarding to web.config logger settting, save logs on specific storage try { switch (globalVal.CloudBreadLoggerSetting) { case "SQL": /// Save log on SQL string strQuery = string.Format("insert into dbo.CloudBreadLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); /// Database connection retry policy RetryPolicy retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.OpenWithRetry(retryPolicy); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQueryWithRetry(retryPolicy); connection.Close(); break; } case "ATS": /// Save log on Azure Table Storage { /// Azure Table Storage connection retry policy var tableStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); CloudStorageAccount storageAccountT = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountT.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy; CloudTable table = tableClient.GetTableReference("CloudBreadLog"); CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); //Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); break; } case "AQS": /// Save log on Azure Queue Storage { /// Azure Queue Storage connection retry policy var queueStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); queueClient.DefaultRequestOptions.RetryPolicy = queueStorageRetryPolicy; CloudQueue queue = queueClient.GetQueueReference("messagestolog"); /// must be lower case CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; CloudQueueMessage Qmessage = new CloudQueueMessage(JsonConvert.SerializeObject(Message)); queue.AddMessage(Qmessage); break; } case "redis": /// todolist - save log on Azure Redis Cache /// yyyymmdd:memberid:Controller:GUID { string redisKey = ""; string redisVal = ""; message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); ; redisKey = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmm") + ":" + message.memberID + ":" + message.Logger + ":" + Guid.NewGuid().ToString(); // guid - too long key size redisVal = JsonConvert.SerializeObject(message); CBRedis.saveRedisLog(redisKey, redisVal, globalVal.CloudBreadGameLogExpTimeDays); } break; //case "DocDB": // /// @todo save log data on Azure DocumentDB // break; default: /// case do nothing break; } } catch (Exception) { /// catch save log error here. throw; } } } return true; }
public static bool RunLog(CBLoggers message) { if (globalVal.CloudBreadLoggerSetting != "") { if (string.IsNullOrEmpty(message.memberID)) { message.memberID = ""; } //ERROR는 바로 DB - CloudBreadErrorLog 로 저장 if (message.Level.ToUpper() == "ERROR") { try { string strQuery = string.Format("insert into dbo.CloudBreadErrorLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.Open(); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQuery(); connection.Close(); } } catch (Exception) { // DB 로깅이 실패했을 경우 throw; } } else { // 조건에 따라 사용자 로그 저장 try { switch (globalVal.CloudBreadLoggerSetting) { case "SQL": //DB로 저장 string strQuery = string.Format("insert into dbo.CloudBreadAdminLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.Open(); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQuery(); connection.Close(); //Console.WriteLine(rowcount); break; } case "ATS": //ATS로 독립 저장 { CloudStorageAccount storageAccountQ = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountQ.CreateCloudTableClient(); var tableClient1 = storageAccountQ.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("CloudBreadAdminLog"); CBATSMessageEntity Message = new CBATSMessageEntity( message.memberID, Guid.NewGuid().ToString() ); //memberid를 파티션키로 쓴다. Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString(); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); break; } case "AQS": //Azure Queue Storage로 저장 { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference("messagestoadminlog"); // 반드시 소문자 CBATSMessageEntity Message = new CBATSMessageEntity( message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString(); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; CloudQueueMessage Qmessage = new CloudQueueMessage(JsonConvert.SerializeObject(Message)); queue.AddMessage(Qmessage); break; } case "DocDB": //DocDB로 저장 break; default: //저장안함 break; } } catch (Exception) { // 로그 저장 실패시 오류를 throw :: 재시도 하는 로직? throw; } } } return true; }
public static bool RunLog(CBLoggers message) { if (globalVal.CloudBreadLoggerSetting != "") { if (string.IsNullOrEmpty(message.memberID)) { message.memberID = ""; } //ERROR는 바로 DB - CloudBreadErrorLog 로 저장 if (message.Level.ToUpper() == "ERROR") { try { string strQuery = string.Format("insert into dbo.CloudBreadErrorLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.Open(); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQuery(); connection.Close(); } } catch (Exception) { // DB 로깅이 실패했을 경우 throw; } } else { // 조건에 따라 사용자 로그 저장 try { switch (globalVal.CloudBreadLoggerSetting) { case "SQL": //DB로 저장 string strQuery = string.Format("insert into dbo.CloudBreadAdminLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.Open(); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQuery(); connection.Close(); //Console.WriteLine(rowcount); break; } case "ATS": //ATS로 독립 저장 { CloudStorageAccount storageAccountQ = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountQ.CreateCloudTableClient(); var tableClient1 = storageAccountQ.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("CloudBreadAdminLog"); CBATSMessageEntity Message = new CBATSMessageEntity( message.memberID, Guid.NewGuid().ToString() ); //memberid를 파티션키로 쓴다. Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString(); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); break; } case "AQS": //Azure Queue Storage로 저장 { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference("messagestoadminlog"); // 반드시 소문자 CBATSMessageEntity Message = new CBATSMessageEntity( message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString(); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; CloudQueueMessage Qmessage = new CloudQueueMessage(JsonConvert.SerializeObject(Message)); queue.AddMessage(Qmessage); break; } case "DocDB": //DocDB로 저장 break; default: //저장안함 break; } } catch (Exception) { // 로그 저장 실패시 오류를 throw :: 재시도 하는 로직? throw; } } } return(true); }
/** * @brief Save log task processor. \n */ public static bool RunLog(CBLoggers message) { if (globalVal.CloudBreadLoggerSetting != "") { if (string.IsNullOrEmpty(message.memberID)) { message.memberID = ""; /// in case of non-member triggered job } /// critical error case, save in ATS CloudBreadErrorLog if (message.Level.ToUpper() == "ERROR") { try { /// Save error log on Azure Table Storage { /// Azure Table Storage connection retry policy var tableStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); CloudStorageAccount storageAccountT = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountT.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy; CloudTable table = tableClient.GetTableReference("CloudBreadErrorLog"); CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); //Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); } } catch (Exception) { /// Catch fail to log on database. Most case database connection or login fail issue. throw; } } else { /// Regarding to web.config logger settting, save logs on specific storage try { switch (globalVal.CloudBreadLoggerSetting) { case "SQL": /// Save log on SQL string strQuery = string.Format("insert into dbo.CloudBreadAdminLog(memberid, jobID, [Thread], [Level], [Logger], [Message], [Exception]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", message.memberID, message.jobID, message.Thread, message.Level, message.Logger, message.Message, message.Exception ); /// Database connection retry policy RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); SqlConnection connection = new SqlConnection(globalVal.DBConnectionString); { connection.OpenWithRetry(retryPolicy); SqlCommand command = new SqlCommand(strQuery, connection); int rowcount = command.ExecuteNonQueryWithRetry(retryPolicy); connection.Close(); break; } case "ATS": /// Save log on Azure Table Storage { /// Azure Table Storage connection retry policy var tableStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); CloudStorageAccount storageAccountT = CloudStorageAccount.Parse(globalVal.StorageConnectionString); CloudTableClient tableClient = storageAccountT.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy; CloudTable table = tableClient.GetTableReference("CloudBreadAdminLog"); CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); //memberid를 파티션키로 쓴다. Message.jobID = message.jobID; Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); Message.Thread = message.Thread; Message.Level = message.Level; Message.Logger = message.Logger; Message.Message = message.Message; Message.Exception = message.Exception; TableOperation insertOperation = TableOperation.Insert(Message); table.Execute(insertOperation); break; } /// AQS does not need CloudBread-Admin-Web //case "AQS": // /// Save log on Azure Queue Storage // { // /// Azure Queue Storage connection retry policy // var queueStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10); // CloudStorageAccount storageAccount = CloudStorageAccount.Parse(globalVal.StorageConnectionString); // CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // queueClient.DefaultRequestOptions.RetryPolicy = queueStorageRetryPolicy; // CloudQueue queue = queueClient.GetQueueReference("messagestoadminlog"); /// must be lower case // CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); // Message.jobID = message.jobID; // Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); // Message.Thread = message.Thread; // Message.Level = message.Level; // Message.Logger = message.Logger; // Message.Message = message.Message; // Message.Exception = message.Exception; // CloudQueueMessage Qmessage = new CloudQueueMessage(JsonConvert.SerializeObject(Message)); // queue.AddMessage(Qmessage); // break; // } /// redis does not need CloudBread-Admin-Web //case "redis": // /// todolist - save log on Azure Redis Cache // /// yyyymmdd:memberid:Controller:GUID // { // string redisKey = ""; // string redisVal = ""; // message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); // redisKey = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmm") + ":" + message.memberID + ":" + message.Logger + ":" + Guid.NewGuid().ToString(); // guid - too long key size // redisVal = JsonConvert.SerializeObject(message); // CBRedis.saveRedisLog(redisKey, redisVal, globalVal.CloudBreadGameLogExpTimeDays); // } // break; //case "DocDB": // /// @todo save log data on Azure DocumentDB // break; default: /// case do nothing break; } } catch (Exception) { /// catch save log error here. throw; } } } return(true); }