Ejemplo n.º 1
0
        //http://stackoverflow.com/questions/1372123/how-to-detect-when-application-terminates

        #endregion Other

        #if !DNXCORE50

        public static void SetNLogTableStorageConnectionStringAndEmailSmtp(NLog.LogFactory p_nLogFactory)
        {
            bool isTargetReconfigureNeeded = false;

            var nLogTableStorageConnString = Configuration["AzureStorageConnStr"];
            if (String.IsNullOrEmpty(nLogTableStorageConnString))
            {
                //mStartupLogger.LogDebug("HQWebApp:AzureStorageConnStr connection string is not found in Config manager");
            }
            else
            {
                var azureStorageTarget = p_nLogFactory.Configuration.FindTargetByName("AzureTable");    // the original one, not the async wrapper
                if (azureStorageTarget == null)
                {
                    //mStartupLogger.LogError("**HQWebApp: nLog.AzureTableStorage target is not found.");
                }
                else
                {
                    var wrapperBase = azureStorageTarget as NLog.Targets.Wrappers.WrapperTargetBase;
                    AzureTableStorageTarget originalTarget = null;
                    if (wrapperBase != null)
                        originalTarget = (AzureTableStorageTarget)(wrapperBase.WrappedTarget);
                    else
                        originalTarget = (AzureTableStorageTarget)azureStorageTarget;
                    originalTarget.TableName = SharedConstants.WebAppLogTableStorageName;
                    originalTarget.ConnectionString = Encoding.UTF8.GetString(Convert.FromBase64String(nLogTableStorageConnString));
                    isTargetReconfigureNeeded = true;
                    //mStartupLogger.LogDebug("**HQWebApp: nLogger.azureTableStorageTarget is set");
                }
            }

            var emailSmtpUser = Configuration["EmailSmtpUser"];
            var emailSmtpPwd = Configuration["EmailSmtpPwd"];
            var emailGyantal = Configuration["EmailGyantal"];
            if (String.IsNullOrEmpty(emailSmtpUser) || String.IsNullOrEmpty(emailSmtpPwd) || String.IsNullOrEmpty(emailGyantal))
            {
                //mStartupLogger.LogDebug("HQWebApp:emailSmtpUser or emailSmtpPwd connection string is not found in Config manager");
            }
            else
            {
                var mailTarget = p_nLogFactory.Configuration.FindTargetByName("Email");    // the original one, not the async wrapper
                if (mailTarget == null)
                {
                    //mStartupLogger.LogError("**HQWebApp: nLog.Email target is not found.");
                }
                else
                {
                    var wrapperBase = mailTarget as NLog.Targets.Wrappers.WrapperTargetBase;
                    MailTarget originalTarget = null;
                    if (wrapperBase != null)
                        originalTarget = (MailTarget)(wrapperBase.WrappedTarget);
                    else
                        originalTarget = (MailTarget)mailTarget;
                    originalTarget.SmtpUserName = Encoding.UTF8.GetString(Convert.FromBase64String(emailSmtpUser));
                    originalTarget.SmtpPassword = Encoding.UTF8.GetString(Convert.FromBase64String(emailSmtpPwd));
                    originalTarget.To = Encoding.UTF8.GetString(Convert.FromBase64String(emailGyantal));
                    isTargetReconfigureNeeded = true;
                    //mStartupLogger.LogDebug("**HQWebApp: nLogger.Email is set");
                }
            }

            if (isTargetReconfigureNeeded)
                p_nLogFactory.ReconfigExistingLoggers();
        }