Beispiel #1
0
        public async Task TraceListener()
        {
            await using var scope = await EventHubScope.CreateAsync(1);

            #region Snippet:EventHubs_Sample10_TraceListener
#if SNIPPET
            var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
            var eventHubName     = "<< NAME OF THE EVENT HUB >>";
#else
            var connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString;
            var eventHubName     = scope.EventHubName;
#endif
            var producer = new EventHubProducerClient(connectionString, eventHubName);

            using AzureEventSourceListener traceListener = AzureEventSourceListener.CreateTraceLogger(EventLevel.LogAlways);

            try
            {
                using var eventBatch = await producer.CreateBatchAsync();

                var eventData = new EventData("This is an event body");

                if (!eventBatch.TryAdd(eventData))
                {
                    throw new Exception($"The event could not be added.");
                }
            }
            finally
            {
                await producer.CloseAsync();
            }
            #endregion
        }
        /// <summary>
        /// Waits for replication to become in status "Mirrored"
        /// </summary>
        /// <param name="client">ANF Client</param>
        /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param>
        /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param>
        /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param>
        /// <returns></returns>
        static public async Task WaitForCompleteReplicationStatus(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60)
        {
            using AzureEventSourceListener listener = AzureEventSourceListener.CreateTraceLogger(EventLevel.Verbose);
            for (int i = 0; i < retries; i++)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec));
                try
                {
                    var status = await client.Volumes.ReplicationStatusMethodAsync(ResourceUriUtils.GetResourceGroup(resourceId),
                                                                                   ResourceUriUtils.GetAnfAccount(resourceId),
                                                                                   ResourceUriUtils.GetAnfCapacityPool(resourceId),
                                                                                   ResourceUriUtils.GetAnfVolume(resourceId));

                    if (status.MirrorState.ToLower().Equals("mirrored"))
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (!(ex.Message.ToLower().Contains("creating") && ex.Message.ToLower().Contains("replication")))
                    {
                        throw;
                    }
                }
            }
        }
 public void TraceLogging()
 {
     #region Snippet:TraceLogging
     // Setup a listener to monitor logged events.
     using AzureEventSourceListener listener = AzureEventSourceListener.CreateTraceLogger();
     #endregion
 }
 public void LoggingLevel()
 {
     #region Snippet:LoggingLevel
     using AzureEventSourceListener consoleListener = AzureEventSourceListener.CreateConsoleLogger(EventLevel.Warning);
     using AzureEventSourceListener traceListener   = AzureEventSourceListener.CreateTraceLogger(EventLevel.Informational);
     #endregion
 }
Beispiel #5
0
        public async Task TraceListener()
        {
            await using var scope = await EventHubScope.CreateAsync(1);

            #region Snippet:EventHubs_Sample10_TraceListener
#if SNIPPET
            var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
            var eventHubName     = "<< NAME OF THE EVENT HUB >>";
#else
            var connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString;
            var eventHubName     = scope.EventHubName;
#endif
            var producer = new EventHubProducerClient(connectionString, eventHubName);

            using AzureEventSourceListener traceListener = AzureEventSourceListener.CreateTraceLogger(EventLevel.LogAlways);

            try
            {
                var events = new[]
                {
                    new EventData("EventOne"),
                    new EventData("EventTwo")
                };

                await producer.SendAsync(events);
            }
            finally
            {
                await producer.CloseAsync();
            }
            #endregion
        }
        static async Task Main(string[] args)
        {
            using AzureEventSourceListener listener = AzureEventSourceListener.CreateTraceLogger(EventLevel.Verbose);

            await ResolveAndParse();
            await ParseAndResolve();
            await NotFound();
        }