none
Proper way to Write to "Microsoft Office Alerts" RRS feed

  • Question

  • I am trying to write to the Event Log "Microsoft Office Alerts' from a Word Add-in written with VB 2013. So far I can write to this log, but the output is not as expected.

    A normal entry in this log would look like:

    Microsoft Word
    Want to save your changes to Document1?
    P1: 200054
    P2: 15.0.4797.1000
    P3:
    P4:

    or in XML

    <EventData>
      <Data>Microsoft Word</Data>
      <Data>Want to save your changes to Document1?</Data>
      <Data>200054</Data>
      <Data>15.0.4797.1000</Data>
      <Data />
      <Data />
    </EventData>

    My entry looks like:

    From Matt%2P1: %3P2: %4P3: %5P4: %6

    or the XML shows I only have 1 line of data.

     <EventData>
      <Data>From Matt</Data>
     </EventData>

    How do I supply the information for P1, P2 etc..?

    Thanks

    Matt

    Monday, March 7, 2016 10:51 PM

Answers

  • Hello David,

    Really thought this was the right forum since my questions was specifically about writing to the General Office Event Log - "Microsoft Office 15 Alerts".

    The good news is I found the answer by reviewing other unanswered questions.

    Thanks to Dave for posting his question

    http://www.codeproject.com/Questions/1002110/EventLog-WriteEvent-Add-Data-Name-Attribute-to-Eve

    Here is what I am using so far.

      Public Shared Sub AddEventlog(strEventMSG As String, strEventLevel As String)
    
            'vbCr added to each to make the error listing look like the rest.
            Dim strEvent1 As String = "MS Word - RprinterAI" & vbCr 'Reporting Application
            Dim strEvent2 As String = strEventMSG & vbCr            'Message
            Dim strEvent3 As String = Globals.ThisAddIn.GetType().Assembly.GetName().Version.ToString & vbCr 'Unknown 0 use for Addin version
            Dim strEvent4 As String = Globals.AIThisAddIn.Application.Build.ToString & vbCr 'Reporting Application version
            Dim strEvent5 As String = strEventLevel & vbCr 'Unused - Severity
            Dim strEvent6 As String                         'Unused - get namem of current document
            If Globals.ThisAddIn.Application.Documents.Count > 0 Then
                strEvent6 = Globals.ThisAddIn.Application.ActiveDocument.FullName & vbCr
            Else
                strEvent6 = "No Documents Open" & vbCr
            End If
    
            Try
                EventLog.WriteEvent("Microsoft Office 15 Alerts", _
                        New EventInstance(300, 0, EventLogEntryType.Information), _
                            {strEvent1, strEvent2, strEvent3, strEvent4, strEvent5, strEvent6})
            Catch ex As SystemException
                MsgBox("Error Add2EventLog - Inform Admin and Restart Word!!", MsgBoxStyle.Critical)
            End Try
    
        End Sub

    Basically, each of the six items are separated by a comma once I got the correct eventlog.writeevent format.

    Now my entries into this log look just like those from the Office programs.

    Thanks again for your effort.

    Matt

    • Proposed as answer by David_JunFeng Thursday, March 10, 2016 1:12 AM
    • Marked as answer by David_JunFeng Sunday, March 20, 2016 2:19 PM
    Wednesday, March 9, 2016 3:41 PM

All replies

  • >>>I am trying to write to the Event Log "Microsoft Office Alerts' from a Word Add-in written with VB 2013. So far I can write to this log, but the output is not as expected.

    According to your description, as far as I know that You start an Office application, such as Outlook, Word, Excel or PowerPoint and you recieve the following error message:

    "<Office Application> experienced a serious problem with the <Add-in Name> add-in. If you have seen this message multiple times, you should disable this add-in and check to see if an update is available. Do you want to disable this add-in?"

    If you examine the Microsoft Office Alerts log you will also find an event with the following parameters:

    Event log: Microsoft Office Alerts
    EventID = 300
    Message =
    Microsoft Office Application
    <Office Application> experienced a serious problem with the <Add-in Name> add-in. If you have seen this message multiple times, you should disable this add-in and check to see if an update is available. Do you want to disable this add-in?

    P1: 700160
    P2: 14.0.6029.1000
    P3: xath
    P4:
    Source = Microsoft Office 14 Alerts (or Microsoft Office 15 Alerts)

    Note: In this error message and event, <Office Application> is replaced with the name of the Office application such as Outlook, Word, Excel or PowerPoint, and <Add-in Name> is replaced with the name of the add-in that experienced the problem.

    For more information, click here to refer about Office Applications experience a serious problem with an add-in

    If you want to write event log, you could also read entries from existing logs and create your own custom event logs. In its simplest form, writing to an event log involves only a few steps to create a sample application. To do this, follow these steps:

    1.Open Visual Studio C#.

    2.Create a new Console application in Visual C#. The Console application creates a public class and an empty Main method for you.

    3.Verify that the project references at least the System.dll file.

    4.Use the using directive on the System and System.Diagnostics namespaces

    5.Use two static methods of the EventLog class to check whether your source exists, and then, if the source does not exist, to create this source that is associated with a particular event log. If the log name that you specify does not exist, the name is created automatically when you write your first entry to the log. By default, if you do not supply a log name to the CreateEventSource method, the log file is named "Application Log."

    if (!EventLog.SourceExists(sSource))
     EventLog.CreateEventSource(sSource,sLog);

    For more information, click here to refer about How to write to an event log by using Visual C#


    Tuesday, March 8, 2016 5:43 AM
  • Hello David,

    Thanks for the reply.  Your answer did not directly address my question.

    First of all, I am already able to write to the event log "Microsoft Office Alerts".

    Secondly, this log seems to be expecting the input in a specific format.  Like the text you posted on how to read the error message describes what each part of the error message means.

    My question is: How to I format the WriteEvent statement so that each of those fields are filled?

    Example:

    Dim strEvent As String
    Dim myLog As New EventLog()
            myLog.Source = "Microsoft Office 15 Alerts"
            strEvent = "From Matt " & vbTab & "Test"
            myLog.WriteEntry(strEvent, EventLogEntryType.Information, 300)

    The above lines produce an event in the "Microsoft Office Alerts" log as  follows:

    From Matt Test%2P1: %3P2: %4P3: %5P4: %6



    How do I specify P1: or P2: ?

    I am not having a problem with the Add-In, I just want to log certain events as they happen to see how often those events happen.

    Is there some special characters I need to enter in my strEvent to differentiate these different variables?

    Should I be using something besides a string variable, such as an object or array?

    Thanks again for your help, I hope this clarifies what I am looking for with this question.

    Matt


    Tuesday, March 8, 2016 3:35 PM
  • Hi, MattReede

    According to your description, since this is the forum to discuss questions and feedback for General Office Development, your issue is related to write Event log, I suggest that you could post your issue on MSDN forum for Visual Basic.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    Thanks for your understanding.
    Wednesday, March 9, 2016 9:55 AM
  • Hello David,

    Really thought this was the right forum since my questions was specifically about writing to the General Office Event Log - "Microsoft Office 15 Alerts".

    The good news is I found the answer by reviewing other unanswered questions.

    Thanks to Dave for posting his question

    http://www.codeproject.com/Questions/1002110/EventLog-WriteEvent-Add-Data-Name-Attribute-to-Eve

    Here is what I am using so far.

      Public Shared Sub AddEventlog(strEventMSG As String, strEventLevel As String)
    
            'vbCr added to each to make the error listing look like the rest.
            Dim strEvent1 As String = "MS Word - RprinterAI" & vbCr 'Reporting Application
            Dim strEvent2 As String = strEventMSG & vbCr            'Message
            Dim strEvent3 As String = Globals.ThisAddIn.GetType().Assembly.GetName().Version.ToString & vbCr 'Unknown 0 use for Addin version
            Dim strEvent4 As String = Globals.AIThisAddIn.Application.Build.ToString & vbCr 'Reporting Application version
            Dim strEvent5 As String = strEventLevel & vbCr 'Unused - Severity
            Dim strEvent6 As String                         'Unused - get namem of current document
            If Globals.ThisAddIn.Application.Documents.Count > 0 Then
                strEvent6 = Globals.ThisAddIn.Application.ActiveDocument.FullName & vbCr
            Else
                strEvent6 = "No Documents Open" & vbCr
            End If
    
            Try
                EventLog.WriteEvent("Microsoft Office 15 Alerts", _
                        New EventInstance(300, 0, EventLogEntryType.Information), _
                            {strEvent1, strEvent2, strEvent3, strEvent4, strEvent5, strEvent6})
            Catch ex As SystemException
                MsgBox("Error Add2EventLog - Inform Admin and Restart Word!!", MsgBoxStyle.Critical)
            End Try
    
        End Sub

    Basically, each of the six items are separated by a comma once I got the correct eventlog.writeevent format.

    Now my entries into this log look just like those from the Office programs.

    Thanks again for your effort.

    Matt

    • Proposed as answer by David_JunFeng Thursday, March 10, 2016 1:12 AM
    • Marked as answer by David_JunFeng Sunday, March 20, 2016 2:19 PM
    Wednesday, March 9, 2016 3:41 PM
  • Hi, MattReede

    Good news! Thank you for sharing the solution with other forum readers.
    Thursday, March 10, 2016 1:12 AM