The error is that you cannot achieve this with WriteEntry , because you need to provide several parameters, as well as the correct EventIdentifier
If you switch to WriteEvent , you can achieve where you are:
var myNewLog = new EventLog("System", ".", "Service Control Manager"); myNewLog.WriteEvent( new EventInstance( (1 << 30) + 7036 ,0) , null , new object[] { "foobar","running" } );
Note that the Eventinstance is loaded with an EventIdentifier, which has 7036 found in the lower 16 bits, but bit 30 (client bit) should be 1, indicating that we have a client code.
Running this code as an administrator gives in the event log:
The foobar service has entered the current state.
with this xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Service Control Manager" Guid="{some-guid-here}" EventSourceName="Service Control Manager" /> <EventID Qualifiers="16384">7036</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2014-01-13T00:13:56.000000000Z" /> <EventRecordID>999999</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>System</Channel> <Computer>internal.example.com</Computer> <Security /> </System> <EventData> <Data Name="param1">foobar</Data> <Data Name="param2">running</Data> <Binary /> </EventData> </Event>
source share