次のコードを使用してアプリケーションイベントログに書き込むと、すべてが正常に機能します。
EventLog log = new EventLog();
log.Source = "Application";
log.WriteEntry("test message", EventLogEntryType.Error);
MSDNや他のすべてのブログのコードを使用すると、セキュリティエラーが発生します(CreateEventSourceによって発生するため推測しています)。
string sSource = "MyWebService";
string sLog = "myApplication";
string sMsg = errorMessage;
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sMsg, EventLogEntryType.Error);
したがって、デフォルトで存在するアプリケーションログに書き込むだけでよい場合、ソースが存在するかどうかを確認する必要がありますか?
EventViewerに書き込む適切な方法は何ですか?