Example #1
0
        private AspNetEventSource() {
            // We need to light up when running on .NET 4.5.1 since we can't compile directly
            // against the protected methods we might need to consume. Only ever try creating
            // this delegate if we're in full trust, otherwise exceptions could happen at
            // inopportune times (such as during invocation).

            if (AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted) {
                MethodInfo writeEventWithRelatedActivityIdCoreMethod = typeof(EventSource).GetMethod(
                    "WriteEventWithRelatedActivityIdCore", BindingFlags.Instance | BindingFlags.NonPublic, null,
                    new Type[] { typeof(int), typeof(Guid*), typeof(int), typeof(EventData*) }, null);

                if (writeEventWithRelatedActivityIdCoreMethod != null) {
                    _writeEventWithRelatedActivityIdCoreDel = (WriteEventWithRelatedActivityIdCoreDelegate)Delegate.CreateDelegate(
                        typeof(WriteEventWithRelatedActivityIdCoreDelegate), this, writeEventWithRelatedActivityIdCoreMethod, throwOnBindFailure: false);
                }
            }
        }
Example #2
0
        private AspNetEventSource()
        {
            // We need to light up when running on .NET 4.5.1 since we can't compile directly
            // against the protected methods we might need to consume. Only ever try creating
            // this delegate if we're in full trust, otherwise exceptions could happen at
            // inopportune times (such as during invocation).

            if (AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted)
            {
                MethodInfo writeEventWithRelatedActivityIdCoreMethod = typeof(EventSource).GetMethod(
                    "WriteEventWithRelatedActivityIdCore", BindingFlags.Instance | BindingFlags.NonPublic, null,
                    new Type[] { typeof(int), typeof(Guid *), typeof(int), typeof(EventData *) }, null);

                if (writeEventWithRelatedActivityIdCoreMethod != null)
                {
                    _writeEventWithRelatedActivityIdCoreDel = (WriteEventWithRelatedActivityIdCoreDelegate)Delegate.CreateDelegate(
                        typeof(WriteEventWithRelatedActivityIdCoreDelegate), this, writeEventWithRelatedActivityIdCoreMethod, throwOnBindFailure: false);
                }
            }
        }