Exemple #1
0
        static void Main(string[] args)
        {
            //
            // New-EventLog -source "MySource" -logname "MyLog" (cf. https://technet.microsoft.com/en-us/library/hh849768.aspx)
            // Run eventvwr
            // Remove-EventLog -logname "MyLog" (cf. https://technet.microsoft.com/en-us/library/hh849786.aspx)
            //


            WriteLine("Option A");
            var eventLog = new EventLog() {Source = "Application"};
            eventLog.WriteEntry("Message Option A");

            WriteLine("Option B");
            var eventLogB = new EventLog() {Source = "MyLog", EnableRaisingEvents = true};
            var eventInstanceB = new EventInstance(0, 1);
            eventLogB.WriteEvent(eventInstanceB, "Message Option B");

            WriteLine("Option C");
            var eventLogC = new EventLog() {Source = "MyLog"};
            eventLogC.WriteEntry("Message Option C", EventLogEntryType.Error);

            WriteLine("Option D");
            var eventLogD = new EventLog() {Source = "MySource", EnableRaisingEvents = true};
            eventLogD.WriteEntry("Message Option D", EventLogEntryType.Error);

            WriteLine("Done.");
            ReadLine();
        }
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            var test = new EventInstance(eventData.EventId, (int)eventData.Task, EventLogEntryType.Warning);
            _eventLog.WriteEvent(test, new string[] { "OpCode=1" });

            _eventLog.WriteEntry("Event Occurring", EventLogEntryType.Information, eventData.EventId, (short)eventData.Task);
        }
 public static void WriteEvent(long EventId, string EventContent, EventLogEntryType EntryType)
 {
     try
     {
         System.Diagnostics.EventInstance theEvtInst = new System.Diagnostics.EventInstance(EventId, 0, EntryType);
         //System.Diagnostics.EventLog.WriteEvent(AppCfgs.CurrentAppCenterID + "KeDuoSysLogs", theEvtInst, EventContent, AppCfgs.ServiceBaseAddress);
     }
     catch
     {
     }
 }
		public void Constructor1 ()
		{
			EventInstance ei = null;

			ei = new EventInstance (5, 10);
			Assert.AreEqual (10, ei.CategoryId, "#A1");
			Assert.AreEqual (5, ei.InstanceId, "#A2");
			Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");

			ei = new EventInstance (0, 0);
			Assert.AreEqual (0, ei.CategoryId, "#B1");
			Assert.AreEqual (0, ei.InstanceId, "#B2");
			Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#B3");

			ei = new EventInstance (uint.MaxValue, ushort.MaxValue);
			Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
			Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
			Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#C3");
		}
Exemple #5
0
 internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
     int engineLifecycleEventId = GetEngineLifecycleEventId(newState);
     if (engineLifecycleEventId != -1)
     {
         Hashtable mapArgs = new Hashtable();
         mapArgs["NewEngineState"] = newState.ToString();
         mapArgs["PreviousEngineState"] = previousState.ToString();
         FillEventArgs(mapArgs, logContext);
         EventInstance entry = new EventInstance((long) engineLifecycleEventId, 4) {
             EntryType = EventLogEntryType.Information
         };
         string eventDetail = this.GetEventDetail("EngineLifecycleContext", mapArgs);
         this.LogEvent(entry, new object[] { newState, previousState, eventDetail });
     }
 }
Exemple #6
0
 internal override void LogCommandLifecycleEvent(Func<LogContext> getLogContext, CommandState newState)
 {
     LogContext logContext = getLogContext();
     int commandLifecycleEventId = GetCommandLifecycleEventId(newState);
     if (commandLifecycleEventId != -1)
     {
         Hashtable mapArgs = new Hashtable();
         mapArgs["NewCommandState"] = newState.ToString();
         FillEventArgs(mapArgs, logContext);
         EventInstance entry = new EventInstance((long) commandLifecycleEventId, 5) {
             EntryType = EventLogEntryType.Information
         };
         string eventDetail = this.GetEventDetail("CommandLifecycleContext", mapArgs);
         this.LogEvent(entry, new object[] { logContext.CommandName, newState, eventDetail });
     }
 }
Exemple #7
0
 public static void WriteEvent(string source, System.Diagnostics.EventInstance instance, params object[] values)
 {
 }
		public void WriteEvent4_Values_Null ()
		{
			if (EventLog.SourceExists ("monotempsource", "."))
				Assert.Ignore ("Event log source 'monotempsource' should not exist.");

			if (EventLog.Exists ("monologtemp", "."))
				Assert.Ignore ("Event log 'monologtemp' should not exist.");

			EventLog.CreateEventSource ("monotempsource", "monologtemp");
			try {
				byte [] data = new byte [] { 23, 54 };
				EventInstance instance = new EventInstance (5, 666,
					EventLogEntryType.Warning);
				EventLog.WriteEvent ("monotempsource", instance, data, (object) null);

				using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
					// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
					Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
					Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
					Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
					Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
					Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
					Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");

					EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#B1");
					Assert.IsNotNull (entry.Category, "#B2");
					Assert.AreEqual ("(666)", entry.Category, "#B3");
					Assert.AreEqual (666, entry.CategoryNumber, "#B4");
					Assert.IsNotNull (entry.Data, "#B5");
					Assert.AreEqual (data, entry.Data, "#B6");
					Assert.AreEqual (EventLogEntryType.Warning, entry.EntryType, "#B7");
					Assert.AreEqual (5, entry.EventID, "#B8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
					Assert.IsNotNull (entry.MachineName, "#B10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
					Assert.IsNotNull (entry.ReplacementStrings, "#B12");
					Assert.AreEqual (1, entry.ReplacementStrings.Length, "#B13");
					Assert.AreEqual (string.Empty, entry.ReplacementStrings [0], "#B14");
					Assert.IsNotNull (entry.Source, "#B15");
					Assert.AreEqual ("monotempsource", entry.Source, "#B16");
					Assert.IsNull (entry.UserName, "#B17");
				}
			} finally {
				if (EventLog.Exists ("monologtemp"))
					EventLog.Delete ("monologtemp");
			}
		}
		[ExpectedException (typeof (ArgumentException))] // Source property was not set before writing to the event log
		public void WriteEvent4_Source_Empty ()
		{
			EventInstance instance = new EventInstance (5, 1,
				EventLogEntryType.Information);
			EventLog.WriteEvent (string.Empty, instance, new byte [0]);
		}
		public void WriteEvent2_Source_DoesNotExist ()
		{
			if (EventLogImplType == NULL_IMPL)
				// test cannot pass with NULL implementation
				return;

			if (EventLog.SourceExists ("monotempsource", "."))
				Assert.Ignore ("Event log source 'monotempsource' should not exist.");

			if (EventLog.SourceExists ("monoothersource", "."))
				Assert.Ignore ("Event log source 'monoothersource' should not exist.");

			if (EventLog.Exists ("monologtemp", "."))
				Assert.Ignore ("Event log 'monologtemp' should not exist.");

			EventLog.CreateEventSource ("monoothersource", "monologtemp");
			try {
				using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
					byte [] data = new byte [] { 23, 54 };
					EventInstance instance = new EventInstance (5, 1,
						EventLogEntryType.Error);
					eventLog.WriteEvent (instance, data, "replace1", "replace2");

					// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
					Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
					Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
					Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
					Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
					Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
					Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");

					EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#B1");
					Assert.IsNotNull (entry.Category, "#B2");
					Assert.AreEqual ("(1)", entry.Category, "#B3");
					Assert.AreEqual (1, entry.CategoryNumber, "#B4");
					Assert.IsNotNull (entry.Data, "#B5");
					Assert.AreEqual (data, entry.Data, "#B6");
					Assert.AreEqual (EventLogEntryType.Error, entry.EntryType, "#B7");
					Assert.AreEqual (5, entry.EventID, "#B8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
					Assert.IsNotNull (entry.MachineName, "#B10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
					Assert.IsNotNull (entry.ReplacementStrings, "#B12");
					Assert.AreEqual (2, entry.ReplacementStrings.Length, "#B13");
					Assert.AreEqual ("replace1", entry.ReplacementStrings [0], "#B14");
					Assert.AreEqual ("replace2", entry.ReplacementStrings [1], "#B15");
					Assert.IsNotNull (entry.Source, "#B16");
					Assert.AreEqual ("monotempsource", entry.Source, "#B17");
					Assert.IsNull (entry.UserName, "#B18");
				}
			} finally {
				if (EventLog.Exists ("monologtemp"))
					EventLog.Delete ("monologtemp");
			}
		}
 public void WriteEvent(EventInstance instance, byte[] data, Object[] values)
 {
 }
 /// <summary>
 /// The signature of this method does not change, it provides everything you need to know about the
 /// log event, you may prepend fixed arguments to the arguments parameters, then simply call write.
 /// BTW, since this is called from the formatter method, or from the exception constructor, you may
 /// assume the current stack is the execution context for the exception.  The exception's StackTrace
 /// will be empty since the exception has not been thrown.
 /// </summary>
 public static void TestCustomEventWriter(string eventLog, string eventSource, int category, EventLogEntryType eventType, long eventId, object[] arguments, Exception error)
 {
     _lastLog = new EventLog(eventLog, ".", eventSource);
     _lastEvent = new EventInstance(eventId, category, eventType);
     _lastArgs = (string[])arguments;
 }
        public void TestFormatResxOptions()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            //the next message id to use when autoLog is enabled.
            builder.Add(".NextMessageId", 5);

            //the format string for the full hresult to a uri.
            builder.Add(".HelpLink", new Uri("http://mydomain/errorcodes.aspx?id={0:x8}"));

            //Trailing message text for event log, can include {0} formats. which are specified before the message-specific values
            builder.Add(".EventMessageFormat", "Trailing message text for event log, can include {0} formats.");

            //Enables the LOG feature to automagically generate log calls on all exception constructors.
            builder.Add(".AutoLog", true);

            //The fully-qualified method used to write the log to the event log
            builder.Add(".AutoLogMethod", String.Format("{0}.TestCustomEventWriter", GetType().FullName));

            //The name of the event source to register, can be qualified with log: "Log-Name/Event-Source"
            builder.Add(".EventSource", "Application/YourAppName");

            //OPTIONAL (default=0): The category id and name for the category of the message, should be unique for this ResX file 
            builder.Add(".EventCategory", 0x0F, "MyCategory");

            //OPTIONAL (default=0): The facility code (256-2047) and name to define for these messages
            builder.Add(".Facility", 258, "MyFacility");

            builder.Add("TestFormatting(int value)", "TestFormatting-{0:x8}", "#MessageId=3");
            builder.Add("TestWarning", "TestWarning", "(int unprinted) #MessageId=251, Severity=Warn");
            builder.Add("TestException(string s, int i)", "TestException-{0}-{1}", ":System.Runtime.InteropServices.COMException");

            string code, resx;
            TestResourceResult result;
            StringWriter captureErr = new StringWriter();
            TextWriter stderr = Console.Error;
            try
            {
                Console.SetError(captureErr);
                result = builder.Compile("-reference:" + GetType().Assembly.Location, out code, out resx);
            }
            finally { Console.SetError(stderr); }

            _lastEvent = null;
            Assert.AreEqual("TestFormatting-000e1234", result.GetValue("TestFormatting", 0x0e1234));
            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Information, _lastEvent.EntryType);
            Assert.AreEqual(0x41020003L, _lastEvent.InstanceId);
            Assert.AreEqual(1, _lastArgs.Length);
            Assert.AreEqual("000e1234", _lastArgs[0]);

            _lastEvent = null;
            Assert.AreEqual("TestWarning", result.GetValue("TestWarning", 3579));
            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Warning, _lastEvent.EntryType);
            Assert.AreEqual(0x810200fbL, _lastEvent.InstanceId);
            Assert.AreEqual(1, _lastArgs.Length);
            Assert.AreEqual("3579", _lastArgs[0]);

            _lastEvent = null;
            COMException error = (COMException)result.CreateException("TestException", "error", 1234);
            Assert.AreEqual("TestException-error-1234", error.Message);
            Assert.AreEqual(unchecked((int)0xe1020005), error.ErrorCode);//5 was auto-assigned by NextMessageId
            Assert.AreEqual("http://mydomain/errorcodes.aspx?id=e1020005", error.HelpLink);

            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Error, _lastEvent.EntryType);
            Assert.AreEqual(0xC1020005L, _lastEvent.InstanceId);
            Assert.AreEqual(2, _lastArgs.Length);
            Assert.AreEqual("error", _lastArgs[0]);
            Assert.AreEqual("1234", _lastArgs[1]);
        }
 public static void WriteEvent(string source, EventInstance instance, byte[] data, Object[] values)
 {
     Contract.Ensures(0 <= source.Length);
     Contract.Ensures(source.Length <= 212);
 }
Exemple #15
0
 public static void WriteEvent(string source, EventInstance instance, byte[] data, params object[] values)
 {
     throw new NotImplementedException();
 }
Exemple #16
0
 public void WriteEvent(EventInstance instance, params object[] values)
 {
     throw new NotImplementedException();
 }
Exemple #17
0
 private void LogPipelineExecutionDetailEvent(LogContext logContext, string pipelineExecutionDetail, int detailSequence, int detailTotal)
 {
     int num = 800;
     Hashtable mapArgs = new Hashtable();
     mapArgs["PipelineExecutionDetail"] = pipelineExecutionDetail;
     mapArgs["DetailSequence"] = detailSequence;
     mapArgs["DetailTotal"] = detailTotal;
     FillEventArgs(mapArgs, logContext);
     EventInstance entry = new EventInstance((long) num, 8) {
         EntryType = EventLogEntryType.Information
     };
     string eventDetail = this.GetEventDetail("PipelineExecutionDetailContext", mapArgs);
     this.LogEvent(entry, new object[] { logContext.CommandLine, eventDetail, pipelineExecutionDetail });
 }
		public void WriteEvent2_Data_Null ()
		{
			if (EventLog.SourceExists ("monotempsource", "."))
				Assert.Ignore ("Event log source 'monotempsource' should not exist.");

			if (EventLog.Exists ("monologtemp", "."))
				Assert.Ignore ("Event log 'monologtemp' should not exist.");

			EventLog.CreateEventSource ("monotempsource", "monologtemp");
			try {
				using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
					EventInstance instance = new EventInstance (5, 444,
						EventLogEntryType.Warning);
					eventLog.WriteEvent (instance, null, "replace1", null, "replace3");

					// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
					Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
					Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
					Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
					Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
					Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
					Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");

					EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#B1");
					Assert.IsNotNull (entry.Category, "#B2");
					Assert.AreEqual ("(444)", entry.Category, "#B3");
					Assert.AreEqual (444, entry.CategoryNumber, "#B4");
					Assert.IsNotNull (entry.Data, "#B5");
					Assert.AreEqual (0, entry.Data.Length, "#B6");
					Assert.AreEqual (EventLogEntryType.Warning, entry.EntryType, "#B7");
					Assert.AreEqual (5, entry.EventID, "#B8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
					Assert.IsNotNull (entry.MachineName, "#B10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
					Assert.IsNotNull (entry.ReplacementStrings, "#B12");
					Assert.AreEqual (3, entry.ReplacementStrings.Length, "#B13");
					Assert.AreEqual ("replace1", entry.ReplacementStrings [0], "#B14");
					Assert.AreEqual (string.Empty, entry.ReplacementStrings [1], "#B15");
					Assert.AreEqual ("replace3", entry.ReplacementStrings [2], "#B16");
					Assert.IsNotNull (entry.Source, "#B17");
					Assert.AreEqual ("monotempsource", entry.Source, "#B18");
					Assert.IsNull (entry.UserName, "#B19");
				}
			} finally {
				if (EventLog.Exists ("monologtemp"))
					EventLog.Delete ("monologtemp");
			}
		}
Exemple #19
0
 internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
 {
     int providerLifecycleEventId = GetProviderLifecycleEventId(newState);
     if (providerLifecycleEventId != -1)
     {
         Hashtable mapArgs = new Hashtable();
         mapArgs["ProviderName"] = providerName;
         mapArgs["NewProviderState"] = newState.ToString();
         FillEventArgs(mapArgs, logContext);
         EventInstance entry = new EventInstance((long) providerLifecycleEventId, 6) {
             EntryType = EventLogEntryType.Information
         };
         string eventDetail = this.GetEventDetail("ProviderLifecycleContext", mapArgs);
         this.LogEvent(entry, new object[] { providerName, newState, eventDetail });
     }
 }
 public void WriteEvent(EventInstance instance, Object[] values)
 {
 }
 public void WriteEvent(EventInstance instance, Object[] values)
 {
 }
Exemple #22
0
		public void WriteEvent (EventInstance instance, byte [] data, params object [] values)
		{
			if (instance == null)
				throw new ArgumentNullException ("instance");

			string [] replacementStrings = null;
			if (values != null) {
				replacementStrings = new string [values.Length];
				for (int i = 0; i < values.Length; i++) {
					object value = values [i];
					if (value == null)
						replacementStrings [i] = string.Empty;
					else
						replacementStrings [i] = values [i].ToString ();
				}
			} else {
				replacementStrings = new string [0];
			}

			WriteEntry (replacementStrings, instance.EntryType, instance
				.InstanceId, (short) instance.CategoryId, data);
		}
		[ExpectedException (typeof (ArgumentException))] // Source property was not set before writing to the event log
		public void WriteEvent2_Source_Empty ()
		{
			using (EventLog eventLog = new EventLog ("monologtemp")) {
				EventInstance instance = new EventInstance (5, 1,
					EventLogEntryType.Information);
				eventLog.WriteEvent (instance, new byte [0], "replace");
			}
		}
Exemple #24
0
		public static void WriteEvent (string source, EventInstance instance, params object [] values)
		{
			WriteEvent (source, instance, null, values);
		}
		public void WriteEvent4 ()
		{
			if (EventLog.SourceExists ("monotempsource", "."))
				Assert.Ignore ("Event log source 'monotempsource' should not exist.");

			if (EventLog.Exists ("monologtemp", "."))
				Assert.Ignore ("Event log 'monologtemp' should not exist.");

			EventLog.CreateEventSource ("monotempsource", "monologtemp");
			try {
				byte [] data = new byte [] { 23, 54 };
				EventInstance instance = new EventInstance (5, 666,
					EventLogEntryType.FailureAudit);
				EventLog.WriteEvent ("monotempsource", instance, data, 5, "new"
					+ Environment.NewLine + "line", true, null);

				using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
					// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
					Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
					Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
					Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
					Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
					Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
					Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");

					EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#B1");
					Assert.IsNotNull (entry.Category, "#B2");
					Assert.AreEqual ("(666)", entry.Category, "#B3");
					Assert.AreEqual (666, entry.CategoryNumber, "#B4");
					Assert.IsNotNull (entry.Data, "#B5");
					Assert.AreEqual (data, entry.Data, "#B6");
					Assert.AreEqual (EventLogEntryType.FailureAudit, entry.EntryType, "#B7");
					Assert.AreEqual (5, entry.EventID, "#B8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
					Assert.IsNotNull (entry.MachineName, "#B10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
					Assert.IsNotNull (entry.ReplacementStrings, "#B12");
					Assert.AreEqual (4, entry.ReplacementStrings.Length, "#B13");
					Assert.AreEqual ("5", entry.ReplacementStrings [0], "#B14");
					Assert.AreEqual ("new" + Environment.NewLine + "line", entry.ReplacementStrings [1], "#B15");
					Assert.AreEqual (true.ToString (), entry.ReplacementStrings [2], "#B16");
					Assert.AreEqual (string.Empty, entry.ReplacementStrings [3], "#B17");
					Assert.IsNotNull (entry.Source, "#B18");
					Assert.AreEqual ("monotempsource", entry.Source, "#B19");
					Assert.IsNull (entry.UserName, "#B20");

					EventLog.WriteEvent ("monotempsource", instance, data);

					entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#C1");
					Assert.IsNotNull (entry.Category, "#C2");
					Assert.AreEqual ("(666)", entry.Category, "#C3");
					Assert.AreEqual (666, entry.CategoryNumber, "#C4");
					Assert.IsNotNull (entry.Data, "#C5");
					Assert.AreEqual (data, entry.Data, "#C6");
					Assert.AreEqual (EventLogEntryType.FailureAudit, entry.EntryType, "#C7");
					Assert.AreEqual (5, entry.EventID, "#C8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#C9");
					Assert.IsNotNull (entry.MachineName, "#C10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#C11");
					Assert.IsNotNull (entry.ReplacementStrings, "#C12");
					Assert.AreEqual (0, entry.ReplacementStrings.Length, "#C13");
					Assert.IsNotNull (entry.Source, "#C14");
					Assert.AreEqual ("monotempsource", entry.Source, "#C15");
					Assert.IsNull (entry.UserName, "#C16");
				}
			} finally {
				if (EventLog.Exists ("monologtemp"))
					EventLog.Delete ("monologtemp");
			}
		}
Exemple #26
0
		public static void WriteEvent (string source, EventInstance instance, byte [] data, params object [] values)
		{
			using (EventLog eventLog = new EventLog ()) {
				eventLog.Source = source;
				eventLog.WriteEvent (instance, data, values);
			}
		}
		public void WriteEvent4_Source_DoesNotExist ()
		{
			if (EventLogImplType == NULL_IMPL)
				// test cannot pass with NULL implementation
				return;

			if (EventLog.SourceExists ("monotempsource", "."))
				Assert.Ignore ("Event log source 'monotempsource' should not exist.");

			bool applicationLogExists = EventLog.Exists ("Application");
			try {
				byte [] data = new byte [] { 23, 54 };
				EventInstance instance = new EventInstance (666, 1,
					EventLogEntryType.Error);
				EventLog.WriteEvent ("monotempsource", instance, data, "replace1", "replace2");

				Assert.IsTrue (EventLog.Exists ("Application"), "#A1");
				Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A2");
				Assert.AreEqual ("Application", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A3");

				if (EventLogImplType == WIN32_IMPL)
					// win32 API does not return entries in order for
					// Application log
					return;

				using (EventLog eventLog = new EventLog ("Application", ".", "monotempsource")) {
					EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
					Assert.IsNotNull (entry, "#B1");
					Assert.IsNotNull (entry.Category, "#B2");
					Assert.AreEqual ("(1)", entry.Category, "#B3");
					Assert.AreEqual (1, entry.CategoryNumber, "#B4");
					Assert.IsNotNull (entry.Data, "#B5");
					Assert.AreEqual (data, entry.Data, "#B6");
					Assert.AreEqual (EventLogEntryType.Error, entry.EntryType, "#B7");
					Assert.AreEqual (666, entry.EventID, "#B8");
					Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
					Assert.IsNotNull (entry.MachineName, "#B10");
					Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
					Assert.IsNotNull (entry.ReplacementStrings, "#B12");
					Assert.AreEqual (2, entry.ReplacementStrings.Length, "#B13");
					Assert.AreEqual ("replace1", entry.ReplacementStrings [0], "#B14");
					Assert.AreEqual ("replace2", entry.ReplacementStrings [1], "#B15");
					Assert.IsNotNull (entry.Source, "#B16");
					Assert.AreEqual ("monotempsource", entry.Source, "#B17");
					Assert.IsNull (entry.UserName, "#B18");
				}
			} finally {
				if (!applicationLogExists) {
					if (EventLog.Exists ("Application"))
						EventLog.Delete ("Application");
				} else {
					if (EventLog.SourceExists ("monotempsource", "."))
						EventLog.DeleteEventSource ("monotempsource", ".");
				}
			}
		}
 private EventInstance CreateEventInstance(TraceEventType severity, int id)
 {
     if (id > 0xffff)
     {
         id = 0xffff;
     }
     if (id < 0)
     {
         id = 0;
     }
     EventInstance instance1 = new EventInstance((long)id, 0);
     if ((severity == TraceEventType.Error) || (severity == TraceEventType.Critical))
     {
         instance1.EntryType = EventLogEntryType.Error;
         return instance1;
     }
     if (severity == TraceEventType.Warning)
     {
         instance1.EntryType = EventLogEntryType.Warning;
         return instance1;
     }
     instance1.EntryType = EventLogEntryType.Information;
     return instance1;
 }
Exemple #29
0
 public void WriteEvent(System.Diagnostics.EventInstance instance, params object[] values)
 {
 }
Exemple #30
0
 public void WriteEvent(EventInstance instance, params object [] values)
 {
     WriteEvent(instance, null, values);
 }
        private EventInstance CreateEventInstance(TraceEventType severity, int id) {
            // Win32 EventLog has an implicit cap at ushort.MaxValue
            // We need to cap this explicitly to prevent larger value 
            // being wrongly casted 
            if (id > ushort.MaxValue)
                id = ushort.MaxValue;

            // Ideally we need to pick a value other than '0' as zero is 
            // a commonly used EventId by most applications 
            if (id < ushort.MinValue)
                id = ushort.MinValue;
            
            EventInstance data = new EventInstance(id, 0);

            if (severity == TraceEventType.Error || severity == TraceEventType.Critical) 
                data.EntryType = EventLogEntryType.Error;
            else if (severity == TraceEventType.Warning)
                data.EntryType = EventLogEntryType.Warning;
            else                
                data.EntryType = EventLogEntryType.Information;

            return data;
        }
Exemple #32
0
 public static void WriteEvent(string source, EventInstance instance, params object [] values)
 {
     WriteEvent(source, instance, null, values);
 }
Exemple #33
0
 internal override void LogEngineHealthEvent(LogContext logContext, int eventId, Exception exception, Dictionary<string, string> additionalInfo)
 {
     Hashtable mapArgs = new Hashtable();
     IContainsErrorRecord record = exception as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         mapArgs["ExceptionClass"] = exception.GetType().Name;
         mapArgs["ErrorCategory"] = record.ErrorRecord.CategoryInfo.Category;
         mapArgs["ErrorId"] = record.ErrorRecord.FullyQualifiedErrorId;
         if (record.ErrorRecord.ErrorDetails != null)
         {
             mapArgs["ErrorMessage"] = record.ErrorRecord.ErrorDetails.Message;
         }
         else
         {
             mapArgs["ErrorMessage"] = exception.Message;
         }
     }
     else
     {
         mapArgs["ExceptionClass"] = exception.GetType().Name;
         mapArgs["ErrorCategory"] = "";
         mapArgs["ErrorId"] = "";
         mapArgs["ErrorMessage"] = exception.Message;
     }
     FillEventArgs(mapArgs, logContext);
     FillEventArgs(mapArgs, additionalInfo);
     EventInstance entry = new EventInstance((long) eventId, 1) {
         EntryType = GetEventLogEntryType(logContext)
     };
     string eventDetail = this.GetEventDetail("EngineHealthContext", mapArgs);
     this.LogEvent(entry, new object[] { mapArgs["ErrorMessage"], eventDetail });
 }
 public void WriteEvent(EventInstance instance, params Object[] values) {
     WriteEvent(instance, null, values);
 }
Exemple #35
0
 private void LogEvent(EventInstance entry, params object[] args)
 {
     try
     {
         this._eventLog.WriteEvent(entry, args);
     }
     catch (ArgumentException)
     {
     }
     catch (InvalidOperationException)
     {
     }
     catch (Win32Exception)
     {
     }
 }
        public void WriteEvent(EventInstance instance, byte[] data, params Object[] values) {
            if (instance == null)
                throw new ArgumentNullException("instance");
            if (Source.Length == 0)
                throw new ArgumentException(SR.GetString(SR.NeedSourceToWrite));

            string currentMachineName = machineName;
            if (!boolFlags[Flag_writeGranted]) {
                EventLogPermission permission = new EventLogPermission(EventLogPermissionAccess.Write, currentMachineName);
                permission.Demand();
                boolFlags[Flag_writeGranted] = true;
            }

            VerifyAndCreateSource(Source, currentMachineName);

            string[] strings = null;
            
            if (values != null) {
                strings = new string[values.Length];
                for (int i=0; i<values.Length; i++) {
                    if (values[i] != null)
                        strings[i] = values[i].ToString();
                    else
                        strings[i] = String.Empty;
                }
            }
            
            InternalWriteEvent((uint) instance.InstanceId, (ushort) instance.CategoryId, instance.EntryType, strings, data, currentMachineName);
        }
Exemple #37
0
 internal override void LogProviderHealthEvent(LogContext logContext, string providerName, Exception exception)
 {
     int num = 300;
     Hashtable mapArgs = new Hashtable();
     mapArgs["ProviderName"] = providerName;
     IContainsErrorRecord record = exception as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         mapArgs["ExceptionClass"] = exception.GetType().Name;
         mapArgs["ErrorCategory"] = record.ErrorRecord.CategoryInfo.Category;
         mapArgs["ErrorId"] = record.ErrorRecord.FullyQualifiedErrorId;
         if ((record.ErrorRecord.ErrorDetails != null) && !string.IsNullOrEmpty(record.ErrorRecord.ErrorDetails.Message))
         {
             mapArgs["ErrorMessage"] = record.ErrorRecord.ErrorDetails.Message;
         }
         else
         {
             mapArgs["ErrorMessage"] = exception.Message;
         }
     }
     else
     {
         mapArgs["ExceptionClass"] = exception.GetType().Name;
         mapArgs["ErrorCategory"] = "";
         mapArgs["ErrorId"] = "";
         mapArgs["ErrorMessage"] = exception.Message;
     }
     FillEventArgs(mapArgs, logContext);
     EventInstance entry = new EventInstance((long) num, 3) {
         EntryType = GetEventLogEntryType(logContext)
     };
     string eventDetail = this.GetEventDetail("ProviderHealthContext", mapArgs);
     this.LogEvent(entry, new object[] { mapArgs["ErrorMessage"], eventDetail });
 }
 public void WriteEvent(EventInstance instance, byte[] data, Object[] values)
 {
 }
Exemple #39
0
 internal override void LogSettingsEvent(LogContext logContext, string variableName, string value, string previousValue)
 {
     int num = 700;
     Hashtable mapArgs = new Hashtable();
     mapArgs["VariableName"] = variableName;
     mapArgs["NewValue"] = value;
     mapArgs["PreviousValue"] = previousValue;
     FillEventArgs(mapArgs, logContext);
     EventInstance entry = new EventInstance((long) num, 7) {
         EntryType = EventLogEntryType.Information
     };
     string eventDetail = this.GetEventDetail("SettingsContext", mapArgs);
     this.LogEvent(entry, new object[] { variableName, value, previousValue, eventDetail });
 }
 public static void WriteEvent(string source, EventInstance instance, byte[] data, Object[] values)
 {
   Contract.Ensures(0 <= source.Length);
   Contract.Ensures(source.Length <= 212);
 }