using Microsoft.Reflection;
+#if !ES_BUILD_AGAINST_DOTNET_V35
+using Contract = System.Diagnostics.Contracts.Contract;
+#else
+using Contract = Microsoft.Diagnostics.Contracts.Internal.Contract;
+#endif
+
#if CORECLR || ES_BUILD_PN
using Internal.Runtime.Augments;
#endif
/// </remarks>
public partial class EventSource : IDisposable
{
+
#if FEATURE_EVENTSOURCE_XPLAT
private static readonly EventListener persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener();
#endif //FEATURE_EVENTSOURCE_XPLAT
if (name == null)
{
- throw new ArgumentException(Resources.GetResourceString("Argument_InvalidTypeName"), nameof(eventSourceType));
+ throw new ArgumentException(SR.Argument_InvalidTypeName, nameof(eventSourceType));
}
return GenerateGuidFromName(name.ToUpperInvariant()); // Make it case insensitive.
}
// User-defined EventCommands should not conflict with the reserved commands.
if ((int)command <= (int)EventCommand.Update && (int)command != (int)EventCommand.SendManifest)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_InvalidCommand"), nameof(command));
+ throw new ArgumentException(SR.EventSource_InvalidCommand, nameof(command));
}
eventSource.SendCommand(null, 0, 0, command, true, EventLevel.LogAlways, EventKeywords.None, commandArguments);
/// </summary>
public override string ToString()
{
- return Resources.GetResourceString("EventSource_ToString", Name, Guid);
+ return SR.Format(SR.EventSource_ToString, Name, Guid);
}
/// <summary>
#if FEATURE_MANAGED_ETW
if (m_eventData[eventId].EnabledForETW)
{
+
#if FEATURE_ACTIVITYSAMPLING
// this code should be kept in sync with WriteEventVarargs().
SessionMask etwSessions = SessionMask.All;
m_traits = traits;
if (m_traits != null && m_traits.Length % 2 != 0)
{
- throw new ArgumentException(Resources.GetResourceString("TraitEven"), nameof(traits));
+ throw new ArgumentException(SR.EventSource_TraitEven, nameof(traits));
}
if (eventSourceGuid == Guid.Empty)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_NeedGuid"));
+ throw new ArgumentException(SR.EventSource_NeedGuid);
}
if (eventSourceName == null)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_NeedName"));
+ throw new ArgumentException(SR.EventSource_NeedName);
}
m_name = eventSourceName;
// which would cause a cryptic IndexOutOfRangeException later if we don't catch it here.
if (!m_eventData[eventId].HasRelatedActivityID)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_NoRelatedActivityId"));
+ throw new ArgumentException(SR.EventSource_NoRelatedActivityId);
}
}
if (!typesMatch)
{
- System.Diagnostics.Debugger.Log(0, null, Resources.GetResourceString("EventSource_VarArgsParameterMismatch") + "\r\n");
+ System.Diagnostics.Debugger.Log(0, null, SR.EventSource_VarArgsParameterMismatch + "\r\n");
}
#endif //!ES_BUILD_PCL
}
}
if (eventDataCount != modifiedParamCount)
{
- ReportOutOfBandMessage(Resources.GetResourceString("EventSource_EventParametersMismatch", eventId, eventDataCount, paramCount), true);
+ ReportOutOfBandMessage(SR.Format(SR.EventSource_EventParametersMismatch, eventId, eventDataCount, paramCount), true);
paramCount = Math.Min(paramCount, eventDataCount);
}
switch (EventProvider.GetLastWriteEventError())
{
case EventProvider.WriteEventErrorCode.EventTooBig:
- ReportOutOfBandMessage(errorPrefix + ": " + Resources.GetResourceString("EventSource_EventTooBig"), true);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(Resources.GetResourceString("EventSource_EventTooBig"), innerEx);
+ ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_EventTooBig, true);
+ if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_EventTooBig, innerEx);
break;
case EventProvider.WriteEventErrorCode.NoFreeBuffers:
- ReportOutOfBandMessage(errorPrefix + ": " + Resources.GetResourceString("EventSource_NoFreeBuffers"), true);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(Resources.GetResourceString("EventSource_NoFreeBuffers"), innerEx);
+ ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_NoFreeBuffers, true);
+ if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_NoFreeBuffers, innerEx);
break;
case EventProvider.WriteEventErrorCode.NullInput:
- ReportOutOfBandMessage(errorPrefix + ": " + Resources.GetResourceString("EventSource_NullInput"), true);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(Resources.GetResourceString("EventSource_NullInput"), innerEx);
+ ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_NullInput, true);
+ if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_NullInput, innerEx);
break;
case EventProvider.WriteEventErrorCode.TooManyArgs:
- ReportOutOfBandMessage(errorPrefix + ": " + Resources.GetResourceString("EventSource_TooManyArgs"), true);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(Resources.GetResourceString("EventSource_TooManyArgs"), innerEx);
+ ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_TooManyArgs, true);
+ if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_TooManyArgs, innerEx);
break;
default:
if (innerEx != null)
commandArgs.dispatcher = GetDispatcher(commandArgs.listener);
if (commandArgs.dispatcher == null && commandArgs.listener != null) // dispatcher == null means ETW dispatcher
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_ListenerNotFound"));
+ throw new ArgumentException(SR.EventSource_ListenerNotFound);
}
if (commandArgs.Arguments == null)
if (commandArgs.listener == null && commandArgs.Arguments.Count > 0 && commandArgs.perEventSourceSessionId != sessionIdBit)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_SessionIdError",
+ throw new ArgumentException(SR.Format(SR.EventSource_SessionIdError,
commandArgs.perEventSourceSessionId + SessionMask.SHIFT_SESSION_TO_KEYWORD,
sessionIdBit + SessionMask.SHIFT_SESSION_TO_KEYWORD));
}
{
if (eventSource != this)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_EventSourceGuidInUse", m_guid));
+ throw new ArgumentException(SR.Format(SR.EventSource_EventSourceGuidInUse, m_guid));
}
}
}
// 5 chunks, so only the largest manifests will hit the pause.
if ((envelope.ChunkNumber % 5) == 0)
{
+#if ES_BUILD_STANDALONE
+ Thread.Sleep(15);
+#else
RuntimeThread.Sleep(15);
+#endif
}
}
}
return null;
#else // ES_BUILD_PCL && ES_BUILD_PN
// Don't use nameof here because the resource doesn't exist on some platforms, which results in a compilation error.
- throw new ArgumentException(Resources.GetResourceString("EventSource", "EventSource_PCLPlatformNotSupportedReflection"));
+ throw new ArgumentException("EventSource_PCLPlatformNotSupportedReflection", "EventSource");
#endif
}
if (eventSourceType.IsAbstract() && (flags & EventManifestOptions.Strict) == 0)
return null;
-#if DEBUG && ES_BUILD_STANDALONE
+#if DEBUG && ES_BUILD_STANDALONE && TEST_SUPPORT
TestSupport.TestHooks.MaybeThrow(eventSourceType,
TestSupport.Category.ManifestError,
"EventSource_CreateManifestAndDescriptors",
if (!typeMatch)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_TypeMustDeriveFromEventSource"));
+ manifest.ManifestError(SR.EventSource_TypeMustDeriveFromEventSource);
}
if (!eventSourceType.IsAbstract() && !eventSourceType.IsSealed())
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_TypeMustBeSealedOrAbstract"));
+ manifest.ManifestError(SR.EventSource_TypeMustBeSealedOrAbstract);
}
}
{
if (eventSourceType.IsAbstract())
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_AbstractMustNotDeclareKTOC", nestedType.Name));
+ manifest.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareKTOC, nestedType.Name));
}
else
{
{
if (eventAttribute != null)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", method.Name, eventAttribute.EventId));
+ manifest.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareEventMethods, method.Name, eventAttribute.EventId));
}
continue;
}
}
else if (eventAttribute.EventId <= 0)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_NeedPositiveId", method.Name), true);
+ manifest.ManifestError(SR.Format(SR.EventSource_NeedPositiveId, method.Name), true);
continue; // don't validate anything else for this event
}
if (method.Name.LastIndexOf('.') >= 0)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_EventMustNotBeExplicitImplementation", method.Name, eventAttribute.EventId));
+ manifest.ManifestError(SR.Format(SR.EventSource_EventMustNotBeExplicitImplementation, method.Name, eventAttribute.EventId));
}
eventId++;
string.Compare(startEventMetadata.Name, 0, taskName, 0, taskName.Length) == 0 &&
string.Compare(startEventMetadata.Name, taskName.Length, s_ActivityStartSuffix, 0, Math.Max(startEventMetadata.Name.Length - taskName.Length, s_ActivityStartSuffix.Length)) == 0)
{
+
// Make the stop event match the start event
eventAttribute.Task = (EventTask)startEventMetadata.Descriptor.Task;
noTask = false;
}
if (noTask && (flags & EventManifestOptions.Strict) != 0) // Throw an error if we can compatibly.
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_StopsFollowStarts"));
+ throw new ArgumentException(SR.EventSource_StopsFollowStarts);
}
}
}
#endif
return;
Error:
- manifest.ManifestError(Resources.GetResourceString("EventSource_EnumKindMismatch", staticField.Name, staticField.FieldType.Name, providerEnumKind));
+ manifest.ManifestError(SR.Format(SR.EventSource_EnumKindMismatch, staticField.Name, staticField.FieldType.Name, providerEnumKind));
}
// Helper used by code:CreateManifestAndDescriptors to add a code:EventData descriptor for a method
int eventArg = GetHelperCallFirstArg(method);
if (eventArg >= 0 && evtId != eventArg)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_MismatchIdToWriteEvent", evtName, evtId, eventArg), true);
+ manifest.ManifestError(SR.Format(SR.EventSource_MismatchIdToWriteEvent, evtName, evtId, eventArg), true);
}
if (evtId < eventData.Length && eventData[evtId].Descriptor.EventId != 0)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_EventIdReused", evtName, evtId, eventData[evtId].Name), true);
+ manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId, eventData[evtId].Name), true);
}
// We give a task to things if they don't have one.
if (eventData[idx].Descriptor.Task == (int)eventAttribute.Task && eventData[idx].Descriptor.Opcode == (int)eventAttribute.Opcode)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_TaskOpcodePairReused",
+ manifest.ManifestError(SR.Format(SR.EventSource_TaskOpcodePairReused,
evtName, evtId, eventData[idx].Name, idx));
// If we are not strict stop on first error. We have had problems with really large providers taking forever. because of many errors.
if ((options & EventManifestOptions.Strict) == 0)
}
if (failure)
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", evtName, evtId));
+ manifest.ManifestError(SR.Format(SR.EventSource_EventMustHaveTaskIfNonDefaultOpcode, evtName, evtId));
}
}
// taskName & opcodeName could be passed in by the caller which has opTab & taskTab handy
// if (!(((int)eventAttribute.Opcode == 0 && evtName == taskName) || (evtName == taskName+opcodeName)))
// {
- // throw new WarningException(Resources.GetResourceString("EventSource_EventNameDoesNotEqualTaskPlusOpcode"));
+ // throw new WarningException(SR.EventSource_EventNameDoesNotEqualTaskPlusOpcode);
// }
if (eventsByName == null)
if (eventsByName.ContainsKey(evtName))
{
- manifest.ManifestError(Resources.GetResourceString("EventSource_EventNameReused", evtName), true);
+ manifest.ManifestError(SR.Format(SR.EventSource_EventNameReused, evtName), true);
}
eventsByName[evtName] = evtName;
EventSourceSettings.EtwSelfDescribingEventFormat;
if ((settings & evtFormatMask) == evtFormatMask)
{
- throw new ArgumentException(Resources.GetResourceString("EventSource_InvalidEventFormat"), nameof(settings));
+ throw new ArgumentException(SR.EventSource_InvalidEventFormat, nameof(settings));
}
// If you did not explicitly ask for manifest, you get self-describing.
0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB,
};
- #endregion
+#endregion
}
/// <summary>
}
- #region private
+#region private
/// <summary>
/// This routine adds newEventSource to the global list of eventSources, it also assigns the
/// ID to the eventSource (which is simply the ordinal in the global list).
// Disallow creating EventListener reentrancy.
if (s_CreatingListener)
{
- throw new InvalidOperationException(Resources.GetResourceString("EventSource_ListenerCreatedInsideCallback"));
+ throw new InvalidOperationException(SR.EventSource_ListenerCreatedInsideCallback);
}
try
/// Used to register AD/Process shutdown callbacks.
/// </summary>
private static bool s_EventSourceShutdownRegistered = false;
- #endregion
+#endregion
}
/// <summary>
return eventSource.EnableEventForDispatcher(dispatcher, eventId, false);
}
- #region private
+#region private
internal EventCommandEventArgs(EventCommand command, IDictionary<string, string> arguments, EventSource eventSource,
EventListener listener, int perEventSourceSessionId, int etwSessionId, bool enable, EventLevel level, EventKeywords matchAnyKeyword)
internal EventKeywords matchAnyKeyword;
internal EventCommandEventArgs nextCommand; // We form a linked list of these deferred commands.
- #endregion
+#endregion
}
/// <summary>
// do the lazy init if you know it is contract based (EventID >= 0)
if (EventId >= 0 && m_payloadNames == null)
{
+
var names = new List<string>();
foreach (var parameter in m_eventSource.m_eventData[EventId].Parameters)
{
}
}
- #region private
+#region private
internal EventWrittenEventArgs(EventSource eventSource)
{
m_eventSource = eventSource;
internal EventOpcode m_opcode;
internal EventLevel m_level;
internal EventKeywords m_keywords;
- #endregion
+#endregion
}
/// <summary>
/// </summary>
public EventActivityOptions ActivityOptions { get; set; }
- #region private
+#region private
EventOpcode m_opcode;
private bool m_opcodeSet;
- #endregion
+#endregion
}
/// <summary>
};
- #region private classes
+#region private classes
#if FEATURE_ACTIVITYSAMPLING
}
}
- #region private
+#region private
/// <summary>
/// Creates a new ActivityFilter that is triggered by 'eventId' from 'source' ever
ActivityFilter m_next; // We create a linked list of these
Action<Guid> m_myActivityDelegate;
- #endregion
+#endregion
};
{
if (value <= 10 || value >= 239)
{
- ManifestError(Resources.GetResourceString("EventSource_IllegalOpcodeValue", name, value));
+ ManifestError(SR.Format(SR.EventSource_IllegalOpcodeValue, name, value));
}
string prevName;
if (opcodeTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal))
{
- ManifestError(Resources.GetResourceString("EventSource_OpcodeCollision", name, prevName, value));
+ ManifestError(SR.Format(SR.EventSource_OpcodeCollision, name, prevName, value));
}
}
opcodeTab[value] = name;
{
if (value <= 0 || value >= 65535)
{
- ManifestError(Resources.GetResourceString("EventSource_IllegalTaskValue", name, value));
+ ManifestError(SR.Format(SR.EventSource_IllegalTaskValue, name, value));
}
string prevName;
if (taskTab != null && taskTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal))
{
- ManifestError(Resources.GetResourceString("EventSource_TaskCollision", name, prevName, value));
+ ManifestError(SR.Format(SR.EventSource_TaskCollision, name, prevName, value));
}
}
if (taskTab == null)
{
if ((value & (value - 1)) != 0) // Is it a power of 2?
{
- ManifestError(Resources.GetResourceString("EventSource_KeywordNeedPowerOfTwo", "0x" + value.ToString("x", CultureInfo.CurrentCulture), name), true);
+ ManifestError(SR.Format(SR.EventSource_KeywordNeedPowerOfTwo, "0x" + value.ToString("x", CultureInfo.CurrentCulture), name), true);
}
if ((flags & EventManifestOptions.Strict) != 0)
{
if (value >= 0x0000100000000000UL && !name.StartsWith("Session", StringComparison.Ordinal))
{
- ManifestError(Resources.GetResourceString("EventSource_IllegalKeywordsValue", name, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
+ ManifestError(SR.Format(SR.EventSource_IllegalKeywordsValue, name, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
}
string prevName;
if (keywordTab != null && keywordTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal))
{
- ManifestError(Resources.GetResourceString("EventSource_KeywordCollision", name, prevName, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
+ ManifestError(SR.Format(SR.EventSource_KeywordCollision, name, prevName, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
}
}
if (keywordTab == null)
{
EventChannel chValue = (EventChannel)value;
if (value < (int)EventChannel.Admin || value > 255)
- ManifestError(Resources.GetResourceString("EventSource_EventChannelOutOfRange", name, value));
+ ManifestError(SR.Format(SR.EventSource_EventChannelOutOfRange, name, value));
else if (chValue >= EventChannel.Admin && chValue <= EventChannel.Debug &&
channelAttribute != null && EventChannelToChannelType(chValue) != channelAttribute.EventChannelType)
{
// we want to ensure developers do not define EventChannels that conflict with the builtin ones,
// but we want to allow them to override the default ones...
- ManifestError(Resources.GetResourceString("EventSource_ChannelTypeDoesNotMatchEventChannelValue",
+ ManifestError(SR.Format(SR.EventSource_ChannelTypeDoesNotMatchEventChannelValue,
name, ((EventChannel)value).ToString()));
}
}
if (channelTab.Count == MaxCountChannels)
- ManifestError(Resources.GetResourceString("EventSource_MaxChannelExceeded"));
+ ManifestError(SR.EventSource_MaxChannelExceeded);
ChannelInfo info;
if (!channelTab.TryGetValue((int)channel, out info))
private string CreateManifestString()
{
+
#if FEATURE_MANAGED_ETW_CHANNELS
// Write out the channels
if (channelTab != null)
// Write out the tasks
if (taskTab != null)
{
+
sb.Append(" <tasks>").AppendLine();
var sortedTasks = new List<int>(taskTab.Keys);
sortedTasks.Sort();
return sb.ToString();
}
- #region private
+#region private
private void WriteNameAndMessageAttribs(StringBuilder stringBuilder, string elementName, string name)
{
stringBuilder.Append(" name=\"").Append(name).Append("\"");
string prevValue;
if (stringTab.TryGetValue(key, out prevValue) && !prevValue.Equals(value))
{
- ManifestError(Resources.GetResourceString("EventSource_DuplicateStringKey", key), true);
+ ManifestError(SR.Format(SR.EventSource_DuplicateStringKey, key), true);
return;
}
if (channelTab == null || !channelTab.TryGetValue((int)channel, out info))
{
if (channel < EventChannel.Admin) // || channel > EventChannel.Debug)
- ManifestError(Resources.GetResourceString("EventSource_UndefinedChannel", channel, eventName));
+ ManifestError(SR.Format(SR.EventSource_UndefinedChannel, channel, eventName));
// allow channels to be auto-defined. The well known ones get their well known names, and the
// rest get names Channel<N>. This allows users to modify the Manifest if they want more advanced features.
AddChannel(channelName, (int)channel, GetDefaultChannelAttribute(channel));
if (!channelTab.TryGetValue((int)channel, out info))
- ManifestError(Resources.GetResourceString("EventSource_UndefinedChannel", channel, eventName));
+ ManifestError(SR.Format(SR.EventSource_UndefinedChannel, channel, eventName));
}
// events that specify admin channels *must* have non-null "Message" attributes
if (resources != null && eventMessage == null)
eventMessage = resources.GetString("event_" + eventName, CultureInfo.InvariantCulture);
if (info.Attribs.EventChannelType == EventChannelType.Admin && eventMessage == null)
- ManifestError(Resources.GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", eventName, info.Name));
+ ManifestError(SR.Format(SR.EventSource_EventWithAdminChannelMustHaveMessage, eventName, info.Name));
return info.Name;
}
#endif
string ret;
if (opcodeTab == null || !opcodeTab.TryGetValue((int)opcode, out ret))
{
- ManifestError(Resources.GetResourceString("EventSource_UndefinedOpcode", opcode, eventName), true);
+ ManifestError(SR.Format(SR.EventSource_UndefinedOpcode, opcode, eventName), true);
ret = null;
}
return ret;
}
if (keyword == null)
{
- ManifestError(Resources.GetResourceString("EventSource_UndefinedKeyword", "0x" + bit.ToString("x", CultureInfo.CurrentCulture), eventName), true);
+ ManifestError(SR.Format(SR.EventSource_UndefinedKeyword, "0x" + bit.ToString("x", CultureInfo.CurrentCulture), eventName), true);
keyword = string.Empty;
}
if (ret.Length != 0 && keyword.Length != 0)
}
else
{
- ManifestError(Resources.GetResourceString("EventSource_UnsupportedMessageProperty", evtName, eventMessage));
+ ManifestError(SR.Format(SR.EventSource_UnsupportedMessageProperty, evtName, eventMessage));
}
}
else if ((chIdx = "&<>'\"\r\n\t".IndexOf(eventMessage[i])) >= 0)
string eventName; // Name of the event currently being processed.
int numParams; // keeps track of the number of args the event has.
List<int> byteArrArgIndices; // keeps track of the index of each byte[] argument
- #endregion
+#endregion
}
/// <summary>
#endif
};
- #endregion
+#endregion
}