linuxmacosmonosystem.diagnosticsetw-eventsource

EventSource logs on mono


I am using EventSource to log events in my library. That library is cross platform meaning it could be used by linux/mac users. I know how EventSource works on windows. Users can view default logs using tools like PerfView or Logman tool or implement EventListener class to direct logs to a different location.

But EventListener class is not available on mono. Where are the events logged by EventSource by default on linux/mac? Are there any tools available to view them?

Please let me know if more details are needed.


Solution

  • Just look at source code for EventLog here. There you will see there are 3 event log implementations on mono:

    1. Windows event log (obviously works only on windows)
    2. Local file even log (logs to local file)
    3. Null event log - just drops everything you log.

    How it chooses one? It looks at environment variable MONO_EVENTLOG_TYPE. If it's not present, and you are not on windows - null even log is chosen (which should answer your question where your logs will go by default).

    If variable is present and equals "local" - it will log to local file. If you want to know where exactly it will put those files, look here. You will see default path for such logs on linux is "/var/lib/mono/eventlog".

    All in all - if you develop cross-platform library, consider using something other than pure EventLog (some library like log4net is already fine, and configurable, and can log to EventLog too, among other options). As noted in comments - you indeed can set that environment variable for current process with SetEnvironmentVariable, but still other concerns remain valid.

    EDIT: Sorry I was a bit confused and answered quite another question :) Now I see you mean ETW. So ETW is Event Tracing for Windows and I doubt it is implemented in mono. In fact you see yourself with a link you provided in comments that EventSource class is just a stub which does nothing. Mono has quite a lot of such stubs so that your .NET code can compile and run, even if some functionality is not implemented. So answer to your question is - ETW is not supported on mono. You can get around that by checking on which platform do you run in your EventSource implementation, and if you run on mono - don't use WriteEvent but instead log to another place (log4net file as an example).