Ejemplo n.º 1
0
        /// <summary>
        /// Adds a log entry to the log table
        /// </summary>
        /// <param name="requestId">
        /// Request Id that uniquely identifies the service request to the commerce server
        /// </param>
        /// <param name="resultCode">
        /// Result code of the service invocation
        /// </param>
        /// <param name="resultSummary">
        /// Summary explanation of the result code
        /// </param>
        /// <param name="config">
        /// The configuration to use to get settings.
        /// </param>
        public static void Add(Guid requestId,
                               ResultCode resultCode,
                               string resultSummary,
                               CommerceConfig config)
        {
            try
            {
                if (config == null)
                {
                    throw new ArgumentNullException("config", "Parameter config cannot be null.");
                }

                if (config.EnableServiceHealth == true)
                {
                    DashboardLogEntity logEntity = new DashboardLogEntity(requestId, resultCode.ToString(), resultSummary);
                    PartnerFactory.AzureTable(config).InsertEntity(logEntity);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception, string.Format("Unable to log the data to azure table : {0} ", exception.Message));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the appropriate Log instance for the current environment.
        /// </summary>
        /// <param name="deploymentId">
        /// * If running in Azure, the ID of the deployment that created the VM hosting this application
        /// * Else null.
        /// </param>
        /// <param name="instanceId">
        /// * If running in Azure, the ID of the role instance currently hosting this application
        /// * Else null.
        /// </param>
        /// <param name="traceListener">
        /// * If running in Azure, the Azure diagnostic monitor trace listener to use for the log.
        /// * Else null.
        /// </param>
        /// <param name="logVerbosity">
        /// Specified the verbosity level for entries to commit to the log.
        /// </param>
        /// <param name="forceEventLog">
        /// Specifies whether to force use of the event log instead of other logging mechanisms.
        /// </param>
        /// <param name="source">
        /// The source under which to log events.
        /// </param>
        /// <param name="configuration">
        /// The configuration to use to get settings.
        /// </param>
        internal static void CreateLogInstance(string deploymentId,
                                               string instanceId,
                                               TraceListener traceListener,
                                               SourceLevels logVerbosity,
                                               bool forceEventLog,
                                               string source,
                                               CommerceConfig configuration)
        {
            lock (CreateLogInstanceLock)
            {
                string dashboardConnectionKey;

                if (General.RunningInAzure == true)
                {
                    // If the event log is not set to be used regardless of environment, create a TraceLog and a listener to
                    // funnel log entries into central storage.
                    if (forceEventLog == false)
                    {
                        Log.Instance = new TraceLog(new List <TraceListener> {
                            traceListener
                        }, logVerbosity)
                        {
                            Source = source
                        };
                    }
                    else
                    {
                        Log.Instance = new EventLogLog(logVerbosity)
                        {
                            Source = source
                        };
                    }

                    // Set the server ID to a value useful in Azure.
                    RequestInformationExtensions.ServerId = String.Format("{0}_{1}", deploymentId,
                                                                          instanceId.Substring(instanceId.LastIndexOf("_", StringComparison.OrdinalIgnoreCase) + 1));

                    dashboardConnectionKey = CloudConfigurationManager.GetSetting(DashboardConnectionString);
                }
                else
                {
                    Log.Instance = new EventLogLog(logVerbosity)
                    {
                        Source = source
                    };

                    dashboardConnectionKey = ConfigurationManager.AppSettings[DashboardConnectionString];
                }

                // Initialize the dashboard table into which a subset of warnings will be logged.
                if (String.IsNullOrEmpty(dashboardConnectionKey) == false)
                {
                    CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(dashboardConnectionKey);
                    PartnerFactory.AzureTable(configuration).Initialize(cloudStorageAccount, DashboardTableName,
                                                                        new ExponentialRetry(TimeSpan.FromSeconds(5), 1));
                }

                // Flag log instance as set so CommerceLog won't attempt to create one.
                CommerceLog.LogInstanceSet = true;
                CommerceLog.Config         = configuration;
            }
        }