internal LegacyDiagnosticTrace(TraceSourceKind sourceType, string traceSourceName, string eventSourceName)
            : base(traceSourceName)
        {
            this.traceSourceType = sourceType;
            this.EventSourceName = eventSourceName;

            try
            {
                this.CreateTraceSource();
                this.AddDomainEventHandlersForCleanup();
            }
#if !NO_CONFIGURATION
            catch (ConfigurationErrorsException)
            {
                throw;
            }
#endif
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                System.Runtime.Diagnostics.EventLogger logger = new System.Runtime.Diagnostics.EventLogger(this.EventSourceName, null);
                logger.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Tracing, (uint)System.Runtime.Diagnostics.EventLogEventId.FailedToSetupTracing, false,
                    e.ToString());
            }
        }
        internal LegacyDiagnosticTrace(TraceSourceKind sourceType, string traceSourceName, string eventSourceName)
            : base(traceSourceName)
        {
            this.traceSourceType = sourceType;
            this.EventSourceName = eventSourceName;

            try
            {
                this.CreateTraceSource();
                this.AddDomainEventHandlersForCleanup();
            }
            catch (ConfigurationErrorsException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                System.Runtime.Diagnostics.EventLogger logger = new System.Runtime.Diagnostics.EventLogger(this.EventSourceName, null);
                logger.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Tracing, (uint)System.Runtime.Diagnostics.EventLogEventId.FailedToSetupTracing, false,
                                e.ToString());
            }
        }
        public EtwDiagnosticTrace(string traceSourceName, Guid etwProviderId)
            : base(traceSourceName)
        {
            try
            {
                this.TraceSourceName = traceSourceName;
                this.EventSourceName = string.Concat(this.TraceSourceName, " ", EventSourceVersion);
                CreateTraceSource();
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

#pragma warning disable 618
                EventLogger logger = new EventLogger(this.EventSourceName, null);
                logger.LogEvent(TraceEventType.Error, TracingEventLogCategory, (uint)System.Runtime.Diagnostics.EventLogEventId.FailedToSetupTracing, false,
                    exception.ToString());
#pragma warning restore 618
            }

            try
            {
                CreateEtwProvider(etwProviderId);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                this.etwProvider = null;
#pragma warning disable 618
                EventLogger logger = new EventLogger(this.EventSourceName, null);
                logger.LogEvent(TraceEventType.Error, TracingEventLogCategory, (uint)System.Runtime.Diagnostics.EventLogEventId.FailedToSetupTracing, false,
                    exception.ToString());
#pragma warning restore 618

            }

            if (this.TracingEnabled || this.EtwTracingEnabled)
            {
#pragma warning disable 618
                this.AddDomainEventHandlersForCleanup();
#pragma warning restore 618
            }
        }
예제 #4
0
        void Initialize()
        {
            if (!this.initialized)
            {
                lock (localSyncObject)
                {
                    if (!this.initialized)
                    {
                        string attributeValue = this.Attributes[PiiTraceSource.LogPii];
                        bool   shouldLogPii   = false;
                        if (!string.IsNullOrEmpty(attributeValue))
                        {
                            if (!bool.TryParse(attributeValue, out shouldLogPii))
                            {
                                shouldLogPii = false;
                            }
                        }

                        if (shouldLogPii)
                        {
#pragma warning disable 618
                            System.Runtime.Diagnostics.EventLogger logger = new System.Runtime.Diagnostics.EventLogger(this.eventSourceName, null);
#pragma warning restore 618
#if !NO_CONFIGURATION
                            if (MachineSettingsSection.EnableLoggingKnownPii)
#else
                            if (false)
#endif
                            {
                                logger.LogEvent(TraceEventType.Information,
                                                (ushort)System.Runtime.Diagnostics.EventLogCategory.MessageLogging,
                                                (uint)System.Runtime.Diagnostics.EventLogEventId.PiiLoggingOn,
                                                false);
                                this.shouldLogPii = true;
                            }
                            else
                            {
                                logger.LogEvent(TraceEventType.Error,
                                                (ushort)System.Runtime.Diagnostics.EventLogCategory.MessageLogging,
                                                (uint)System.Runtime.Diagnostics.EventLogEventId.PiiLoggingNotAllowed,
                                                false);
                            }
                        }
                        this.initialized = true;
                    }
                }
            }
        }
        void Initialize()
        {
            if (!this.initialized)
            {
                lock (localSyncObject)
                {
                    if (!this.initialized)
                    {
                        string attributeValue = this.Attributes[PiiTraceSource.LogPii];
                        bool shouldLogPii = false;
                        if (!string.IsNullOrEmpty(attributeValue))
                        {
                            if (!bool.TryParse(attributeValue, out shouldLogPii))
                            {
                                shouldLogPii = false;
                            }
                        }

                        if (shouldLogPii)
                        {
#pragma warning disable 618
                            System.Runtime.Diagnostics.EventLogger logger = new System.Runtime.Diagnostics.EventLogger(this.eventSourceName, null);
#pragma warning restore 618
#if !NO_CONFIGURATION
                            if (MachineSettingsSection.EnableLoggingKnownPii)
#else
                            if (false)
#endif
                            {
                                logger.LogEvent(TraceEventType.Information,
                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.MessageLogging,
                                    (uint)System.Runtime.Diagnostics.EventLogEventId.PiiLoggingOn,
                                    false);
                                this.shouldLogPii = true;
                            }
                            else
                            {
                                logger.LogEvent(TraceEventType.Error,
                                        (ushort)System.Runtime.Diagnostics.EventLogCategory.MessageLogging,
                                        (uint)System.Runtime.Diagnostics.EventLogEventId.PiiLoggingNotAllowed,
                                        false);
                            }
                        }
                        this.initialized = true;
                    }
                }
            }
        }
예제 #6
0
#pragma warning disable 56500
        internal void TraceFailFast(string message)
        {
            System.Runtime.Diagnostics.EventLogger logger = null;
            try
            {
#pragma warning disable 618
                logger = new System.Runtime.Diagnostics.EventLogger(this.eventSourceName, this.diagnosticTrace);
#pragma warning restore 618
            }
            finally
            {
#pragma warning disable 618
                TraceFailFast(message, logger);
#pragma warning restore 618
            }
        }
예제 #7
0
#pragma warning disable 56500
        internal void TraceFailFast(string message)
        {
            System.Runtime.Diagnostics.EventLogger logger = null;
            try
            {
#pragma warning disable 618
                logger = new System.Runtime.Diagnostics.EventLogger(this.eventSourceName, this.diagnosticTrace);
#pragma warning restore 618
            }
            finally
            {
#pragma warning disable 618
                TraceFailFast(message, logger);
#pragma warning restore 618
            }
        }
예제 #8
0
 internal static void TraceFailFast(string message, System.Runtime.Diagnostics.EventLogger logger)
 {
     try
     {
         if (logger != null)
         {
             string stackTrace = null;
             try
             {
                 stackTrace = new StackTrace().ToString();
             }
             catch (Exception exception)
             {
                 stackTrace = exception.Message;
             }
             finally
             {
                 logger.LogEvent(TraceEventType.Critical,
                                 (ushort)EventLogCategory.FailFast,
                                 (uint)EventLogEventId.FailFast,
                                 message,
                                 stackTrace);
             }
         }
     }
     catch (Exception e)
     {
         if (logger != null)
         {
             logger.LogEvent(TraceEventType.Critical,
                             (ushort)EventLogCategory.FailFast,
                             (uint)EventLogEventId.FailFastException,
                             e.ToString());
         }
         throw;
     }
 }
 public static EventLogger UnsafeCreateEventLogger(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     EventLogger logger = new EventLogger();
     logger.SetLogSourceName(eventLogSourceName, diagnosticTrace);
     return logger;
 }
예제 #10
0
		public EtwDiagnosticTrace(string traceSourceName, Guid etwProviderId) : base(traceSourceName)
		{
			try
			{
				this.TraceSourceName = traceSourceName;
				base.EventSourceName = string.Concat(this.TraceSourceName, " ", "4.0.0.0");
				this.CreateTraceSource();
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				if (!Fx.IsFatal(exception))
				{
					EventLogger eventLogger = new EventLogger(base.EventSourceName, null);
					string[] str = new string[1];
					str[0] = exception.ToString();
					eventLogger.LogEvent(TraceEventType.Error, 4, -1073676188, false, str);
				}
				else
				{
					throw;
				}
			}
			try
			{
				this.CreateEtwProvider(etwProviderId);
			}
			catch (Exception exception3)
			{
				Exception exception2 = exception3;
				if (!Fx.IsFatal(exception2))
				{
					this.etwProvider = null;
					EventLogger eventLogger1 = new EventLogger(base.EventSourceName, null);
					string[] strArrays = new string[1];
					strArrays[0] = exception2.ToString();
					eventLogger1.LogEvent(TraceEventType.Error, 4, -1073676188, false, strArrays);
				}
				else
				{
					throw;
				}
			}
			if (base.TracingEnabled || this.EtwTracingEnabled)
			{
				base.AddDomainEventHandlersForCleanup();
			}
		}
예제 #11
0
        public void UnsafeLogEvent(TraceEventType type, ushort eventLogCategory, uint eventId, bool shouldTrace, string[] values)
        {
            string empty;

            if (EventLogger.logCountForPT < 5)
            {
                try
                {
                    int      length    = 0;
                    string[] strArrays = new string[(int)values.Length + 2];
                    for (int i = 0; i < (int)values.Length; i++)
                    {
                        string str = values[i];
                        if (string.IsNullOrEmpty(str))
                        {
                            str = string.Empty;
                        }
                        else
                        {
                            str = EventLogger.NormalizeEventLogParameter(str);
                        }
                        strArrays[i] = str;
                        length       = length + str.Length + 1;
                    }
                    string str1 = EventLogger.NormalizeEventLogParameter(this.UnsafeGetProcessName());
                    strArrays[(int)strArrays.Length - 2] = str1;
                    length = length + str1.Length + 1;
                    int    num  = this.UnsafeGetProcessId();
                    string str2 = num.ToString(CultureInfo.InvariantCulture);
                    strArrays[(int)strArrays.Length - 1] = str2;
                    length = length + str2.Length + 1;
                    if (length > 0x6400)
                    {
                        int length1 = 0x6400 / (int)strArrays.Length - 1;
                        for (int j = 0; j < (int)strArrays.Length; j++)
                        {
                            if (strArrays[j].Length > length1)
                            {
                                strArrays[j] = strArrays[j].Substring(0, length1);
                            }
                        }
                    }
                    SecurityIdentifier user     = WindowsIdentity.GetCurrent().User;
                    byte[]             numArray = new byte[user.BinaryLength];
                    user.GetBinaryForm(numArray, 0);
                    IntPtr[]   intPtrArray   = new IntPtr[(int)strArrays.Length];
                    GCHandle   gCHandle      = new GCHandle();
                    GCHandle[] gCHandleArray = null;
                    try
                    {
                        gCHandle      = GCHandle.Alloc(intPtrArray, GCHandleType.Pinned);
                        gCHandleArray = new GCHandle[(int)strArrays.Length];
                        for (int k = 0; k < (int)strArrays.Length; k++)
                        {
                            gCHandleArray[k] = GCHandle.Alloc(strArrays[k], GCHandleType.Pinned);
                            intPtrArray[k]   = gCHandleArray[k].AddrOfPinnedObject();
                        }
                        this.UnsafeWriteEventLog(type, eventLogCategory, eventId, strArrays, numArray, gCHandle);
                    }
                    finally
                    {
                        if (gCHandle.AddrOfPinnedObject() != IntPtr.Zero)
                        {
                            gCHandle.Free();
                        }
                        if (gCHandleArray != null)
                        {
                            GCHandle[] gCHandleArray1 = gCHandleArray;
                            for (int l = 0; l < (int)gCHandleArray1.Length; l++)
                            {
                                GCHandle gCHandle1 = gCHandleArray1[l];
                                gCHandle1.Free();
                            }
                        }
                    }
                    if (shouldTrace && this.diagnosticTrace != null && this.diagnosticTrace.IsEnabled())
                    {
                        Dictionary <string, string> strs = new Dictionary <string, string>((int)strArrays.Length + 4);
                        strs["CategoryID.Name"]  = "EventLogCategory";
                        strs["CategoryID.Value"] = eventLogCategory.ToString(CultureInfo.InvariantCulture);
                        strs["InstanceID.Name"]  = "EventId";
                        strs["InstanceID.Value"] = eventId.ToString(CultureInfo.InvariantCulture);
                        for (int m = 0; m < (int)values.Length; m++)
                        {
                            Dictionary <string, string> strs1 = strs;
                            string str3 = string.Concat("Value", m.ToString(CultureInfo.InvariantCulture));
                            if (values[m] == null)
                            {
                                empty = string.Empty;
                            }
                            else
                            {
                                empty = DiagnosticTraceBase.XmlEncode(values[m]);
                            }
                            strs1.Add(str3, empty);
                        }
                        this.diagnosticTrace.TraceEventLogEvent(type, new DictionaryTraceRecord(strs));
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                }
                if (this.isInPartialTrust)
                {
                    EventLogger.logCountForPT = EventLogger.logCountForPT + 1;
                }
            }
        }