Whenever working with a client that wants to build custom .NET code around there InfoPath forms I've always found it useful creating a new Event Log. In most cases a new Event Source would also be created for each new form that's created. Doing this gives the ability to easily identify what errors are occurring in the custom .NET code and which form is causing it. The code written to accomplish this is pretty straight forward and was originally done several years ago. The only drawback was it didn't read from a file to get its information but was hard coded in the code instead. It wasn't a big deal for most clients because the developers were creating the forms and they just updated Event Log program during the process. Several days ago there was a need to make the program usable for Administrators without the need of a recompile each time a new form was deployed.
With not having much time to think about it I decided to build a XML file as the source and have the console application load the xml file and bind it to a Class. The addition of this extra functionality wasn't drastic and it actually only needed a new Class, three new additional lines of code and modification of some of the original code.
By no means do I profess to be a .NET coding expert and I'm sure there is better ways of doing this but below is how it was done.
The code was written with Visual Studio 2005 and in VB.NET. It was done this way because of the client requirements. If somebody would like the example in C# please email me and I can post a C# version.
The code was built in a VB.NET Console application and the project was named "CreateEventLogSource" and the code file was also named "CreateEventLogSource".
The Class that was used for binding to XML was created as a XSD and then converted to .NET Class with the XSD.EXE tool. Information on the XSD.EXE tool can be found at the following link. http://msdn2.microsoft.com/en-us/library/x6c1kb0s.aspx

While building the XSD file I also modified it manually set the properties "minOccurs" to "0" and "maxOccurs" to "unbounded" and this can be seen below. You can also do this by using the properties window for the "EventLogSourceItem" Element in the second ComplexType box.

The XML file was based off the XSD and built in Visual Studio. This was accomplished by copying the XSD to the "C:Program FilesMicrosoft Visual Studio 8XmlSchemas" directory. Then adding a new XML file to the project and adding a new line with the property "xmlns=http://tempuri.org/EventLogSource.xsd" as seen below. By doing this it gave me IntelliSense for building the rest of my xml document. The http://tempuri.org/EventLogSource.xsd appeared in the drop down list once "xmlns=" was typed.

The code module for the project had the following "Imports"

and defined fields.

The code between the "Try Catch" statement was the following.

As you can see by reading the code the XML file is being added to a "StreamReader", "XmlSerializer" is being created based of the Class that was created from the XSD file and XML content is bound to the Class created from the XSD file.
The Event Log object is then created and the data records are looped through with "For Each" statement. Inside the "For Each" statement it first verifies if the entry already exist and if so it then reads the next record. If it doesn't exist the necessary properties are set and event source and log is created. Then it writes a new entry to the log and writes a message to the console application screen verifying the completion.
Once it's done reading all the data it then writes to the console application screen with the last messages and pauses for a response.
The "Catch" and "Finally" sections are very straight forward and shown below.


As you can see it is pretty straight forward code and nothing fancy and last thing that I did to make even more user friendly was create a deployment project that creates a MSI for deploying the EXE and XML file.
As always any feedback is welcome on how to do something better or easier.
Cheers.