当前位置: 首页>>代码示例>>C#>>正文


C# NLog.ReconfigExistingLoggers方法代码示例

本文整理汇总了C#中NLog.ReconfigExistingLoggers方法的典型用法代码示例。如果您正苦于以下问题:C# NLog.ReconfigExistingLoggers方法的具体用法?C# NLog.ReconfigExistingLoggers怎么用?C# NLog.ReconfigExistingLoggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NLog的用法示例。


在下文中一共展示了NLog.ReconfigExistingLoggers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetNLogTableStorageConnectionStringAndEmailSmtp

        //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();
        }
开发者ID:gyantal,项目名称:SQHealthMonitor,代码行数:70,代码来源:Startup.cs


注:本文中的NLog.ReconfigExistingLoggers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。