我遇到了将事件写入Windows事件日志的问题。我已经看过帖子,我认为我做得正确,但在事件查看器中仍然出现以下错误:将消息写入应用程序事件日志
消息资源存在但消息未在字符串/消息表中找到
有没有人有什么想法我失踪?
我有在维克斯安装程序创建的事件源:
<Fragment>
<PropertyRef Id="NETFRAMEWORK35"/>
<PropertyRef Id="NETFRAMEWORK20"/>
<PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR"/>
<PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR64" />
<Component Id='EventSource'
Directory='INSTALLDIR'
Guid='F382AAC5-F7C5-46A4-95CF-EA7724DXXXXX' >
<Condition>ALLUSERS</Condition>
<?if $(var.Platform) = x64 ?>
<util:EventSource Log='Application'
Name='MySource'
EventMessageFile='[NETFRAMEWORK20INSTALLROOTDIR64]EventLogMessages.dll'
KeyPath='yes' />
<?else ?>
<util:EventSource Log='Application'
Name='MySource'
EventMessageFile='[NETFRAMEWORK20INSTALLROOTDIR]EventLogMessages.dll'
KeyPath='yes' />
<?endif ?>
</Component>
</Fragment>
这里是我的C#代码,我写到事件日志:
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 + "]";
}
}
}
什么是示踪.Misc.Error?全源样本? – Kiquenet 2014-06-04 10:59:34