title: Writing messages to Application Event Log
body: <p>I am running into an issue writing events to the Windows Event Log.  I have looked through the posts and I think I am doing it correctly, but I still get the following error in the event viewer:</p>
  
  <p><strong>the message resource is present but the message is not found in the string/message table</strong></p>
  
  <p>Does anyone have any ideas on what I am missing?</p>
  
  <p>I am having the event source created in the WIX installer:</p>
  
  <pre><code>&lt;Fragment&gt;
      &lt;PropertyRef Id="NETFRAMEWORK35"/&gt;
      &lt;PropertyRef Id="NETFRAMEWORK20"/&gt;
      &lt;PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR"/&gt;
      &lt;PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR64" /&gt;
  
      &lt;Component Id='EventSource'
                 Directory='INSTALLDIR'
                 Guid='F382AAC5-F7C5-46A4-95CF-EA7724DXXXXX' &gt;
          &lt;Condition&gt;ALLUSERS&lt;/Condition&gt;
          &lt;?if $(var.Platform) = x64 ?&gt;
              &lt;util:EventSource Log='Application'
                      Name='MySource'
                      EventMessageFile='[NETFRAMEWORK20INSTALLROOTDIR64]EventLogMessages.dll'
                      KeyPath='yes' /&gt;
          &lt;?else ?&gt;
              &lt;util:EventSource Log='Application'
                      Name='MySource'
                      EventMessageFile='[NETFRAMEWORK20INSTALLROOTDIR]EventLogMessages.dll'
                      KeyPath='yes' /&gt;
          &lt;?endif ?&gt;
      &lt;/Component&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>And here is my C# code where I write to the Event Log:</p>
  
  <pre><code>public class Log
  {
      private const string EventSource = "MySource";
      private const string EventLog = "Application";
      private static EventLog _logger = null;
  
      private static void InitLogger()
      {
          if (!System.Diagnostics.EventLog.SourceExists(EventSource))
          {
              System.Diagnostics.EventLog.CreateEventSource(EventSource, EventLog);
          }
          _logger = new EventLog() { Source = EventSource, Log = EventLog };
      }
  
      public static void Write(EventLogEntryType entryType, string format, params object[] args)
      {
          string entry = _Format(format, args);
  
          try
          {
              if (_logger == null)
                  InitLogger();
              _logger.WriteEntry(entry, entryType, 1);
          }
          catch (Exception ex)
          {
              Tracer.Misc.Error("Could not write to event log: {0}", entry);
          }
  
      }
  
      private static string _Format(string format, object[] args)
      {
          if ((args == null) || (args.Length == 0))
              return format;
  
          try
          {
              return String.Format(format, args);
          }
          catch (Exception e)
          {
              return format + " [Format Exception:" + e.Message + "]";
          }
      }
  }
  </code></pre>