| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information.using System; |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Diagnostics.Tracing; |
| | 8 | | using System.Fabric; |
| | 9 | |
|
| | 10 | | [EventSource(Name = "Microsoft-Azure-EventHubs-ServiceFabricProcessor")] |
| | 11 | | internal sealed class EventProcessorEventSource : EventSource |
| | 12 | | { |
| 2 | 13 | | public static readonly EventProcessorEventSource Current = new EventProcessorEventSource(); |
| | 14 | |
|
| | 15 | | // Instance constructor is private to enforce singleton semantics |
| 4 | 16 | | private EventProcessorEventSource() : base() { } |
| | 17 | |
|
| | 18 | | #region Keywords |
| | 19 | | // Event keywords can be used to categorize events. |
| | 20 | | // Each keyword is a bit flag. A single event can be associated with multiple keywords (via EventAttribute.Keywo |
| | 21 | | // Keywords must be defined as a public class named 'Keywords' inside EventSource that uses them. |
| | 22 | | public static class Keywords |
| | 23 | | { |
| | 24 | | public const EventKeywords Requests = (EventKeywords)0x1L; |
| | 25 | | public const EventKeywords ServiceInitialization = (EventKeywords)0x2L; |
| | 26 | | } |
| | 27 | | #endregion |
| | 28 | |
|
| | 29 | | #region Events |
| | 30 | | // Define an instance method for each event you want to record and apply an [Event] attribute to it. |
| | 31 | | // The method name is the name of the event. |
| | 32 | | // Pass any parameters you want to record with the event (only primitive integer types, DateTime, Guid & string |
| | 33 | | // Each event method implementation should check whether the event source is enabled, and if it is, call WriteEv |
| | 34 | | // The number and types of arguments passed to every event method must exactly match what is passed to WriteEven |
| | 35 | | // Put [NonEvent] attribute on all methods that do not define an event. |
| | 36 | | // For more information see https://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx |
| | 37 | |
|
| | 38 | | [NonEvent] |
| | 39 | | public void Message(string message, params object[] args) |
| | 40 | | { |
| 4 | 41 | | if (this.IsEnabled()) |
| | 42 | | { |
| 0 | 43 | | string finalMessage = string.Format(message, args); |
| 0 | 44 | | Message(finalMessage); |
| | 45 | | } |
| 4 | 46 | | } |
| | 47 | |
|
| | 48 | | private const int MessageEventId = 1; |
| | 49 | | [Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")] |
| | 50 | | public void Message(string message) |
| | 51 | | { |
| 900 | 52 | | if (this.IsEnabled()) |
| | 53 | | { |
| 0 | 54 | | WriteEvent(MessageEventId, message); |
| | 55 | | } |
| 900 | 56 | | } |
| | 57 | |
|
| | 58 | | [NonEvent] |
| | 59 | | public void ServiceMessage(StatefulServiceContext serviceContext, string message, params object[] args) |
| | 60 | | { |
| 0 | 61 | | if (this.IsEnabled()) |
| | 62 | | { |
| 0 | 63 | | string finalMessage = string.Format(message, args); |
| 0 | 64 | | ServiceMessage( |
| 0 | 65 | | serviceContext.ServiceName.ToString(), |
| 0 | 66 | | serviceContext.ServiceTypeName, |
| 0 | 67 | | serviceContext.ReplicaId, |
| 0 | 68 | | serviceContext.PartitionId, |
| 0 | 69 | | serviceContext.CodePackageActivationContext.ApplicationName, |
| 0 | 70 | | serviceContext.CodePackageActivationContext.ApplicationTypeName, |
| 0 | 71 | | serviceContext.NodeContext.NodeName, |
| 0 | 72 | | finalMessage); |
| | 73 | | } |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private const int ServiceMessageEventId = 2; |
| | 77 | | [Event(ServiceMessageEventId, Level = EventLevel.Informational, Message = "{7}")] |
| | 78 | | private |
| | 79 | | void ServiceMessage( |
| | 80 | | string serviceName, |
| | 81 | | string serviceTypeName, |
| | 82 | | long replicaOrInstanceId, |
| | 83 | | Guid partitionId, |
| | 84 | | string applicationName, |
| | 85 | | string applicationTypeName, |
| | 86 | | string nodeName, |
| | 87 | | string message) |
| | 88 | | { |
| 0 | 89 | | WriteEvent(ServiceMessageEventId, serviceName, serviceTypeName, replicaOrInstanceId, partitionId, applicatio |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | private const int ServiceTypeRegisteredEventId = 3; |
| | 93 | | [Event(ServiceTypeRegisteredEventId, Level = EventLevel.Informational, Message = "Service host process {0} regis |
| | 94 | | public void ServiceTypeRegistered(int hostProcessId, string serviceType) |
| | 95 | | { |
| 0 | 96 | | WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType); |
| 0 | 97 | | } |
| | 98 | |
|
| | 99 | | private const int ServiceHostInitializationFailedEventId = 4; |
| | 100 | | [Event(ServiceHostInitializationFailedEventId, Level = EventLevel.Error, Message = "Service host initialization |
| | 101 | | public void ServiceHostInitializationFailed(string exception) |
| | 102 | | { |
| 0 | 103 | | WriteEvent(ServiceHostInitializationFailedEventId, exception); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | // A pair of events sharing the same name prefix with a "Start"/"Stop" suffix implicitly marks boundaries of an |
| | 107 | | // These activities can be automatically picked up by debugging and profiling tools, which can compute their exe |
| | 108 | | // and other statistics. |
| | 109 | | private const int ServiceRequestStartEventId = 5; |
| | 110 | | [Event(ServiceRequestStartEventId, Level = EventLevel.Informational, Message = "Service request '{0}' started", |
| | 111 | | public void ServiceRequestStart(string requestTypeName) |
| | 112 | | { |
| 0 | 113 | | WriteEvent(ServiceRequestStartEventId, requestTypeName); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | private const int ServiceRequestStopEventId = 6; |
| | 117 | | [Event(ServiceRequestStopEventId, Level = EventLevel.Informational, Message = "Service request '{0}' finished", |
| | 118 | | public void ServiceRequestStop(string requestTypeName, string exception = "") |
| | 119 | | { |
| 0 | 120 | | WriteEvent(ServiceRequestStopEventId, requestTypeName, exception); |
| 0 | 121 | | } |
| | 122 | | #endregion |
| | 123 | | } |
| | 124 | | } |