SBarnes wrote:Will the self hosted api write to the event log with some code added such as the below provided the user the service is running under has the correct permissions.
- Code: Select all
public void LogToEventLog(string Message, System.Diagnostics.EventLogEntryType EventLogEntryType)
{
System.Diagnostics.EventLog Log = new System.Diagnostics.EventLog("Application");
Log.Source = string.Format("Jiwa Plugin : {0}", "REST API");
Log.WriteEntry(Message, EventLogEntryType);
Log.Close();
}
Yes, that should work, but I'd use a different source so your logging isn't wrapped in ugly "The description for Event ID %n from source Application cannot be found" errors.
This blog post has a good write-up on it - the executive summary is to use source of ".NET Runtime" and event id of 1000.
So, if you've imported the necessary namespace, this should be all you need:
- Code: Select all
EventLog.WriteEntry(".NET Runtime", "this is my log message", EventLogEntryType.Warning, 1000);
When we do install Jiwa we do try to register ourselves as a source (which is one of the reasons administrator permissions are required to install) - but we don't create our own Event Message File - so I think that's why our logging to the event log has always been incorrect. We have that logged already as
DEV-8736.