The SPGuidance package delivers a set of components to ease certain administration tasks with SP 2010, for example logging.
It hooks in to the built-in SharePoint logging functionality and exposes a set of classes to easily log your own events in the event log, ULS logs or any custom log sources, like a database.
If one would look into this model, you will find that a diagnostic area corresponds to an event source in the event logs. For instance, if I register a diagnostic area called Boom.MyCustomApplication, the event source mentioned in the logs would read the same. This allows support engineers to easily track the source of the event and act accordingly.
However, although the diagnostic area corresponds to the event source, they are not the same. You can register diagnostic areas using the logging component of the SPGuidance set, but this does not mean a corresponding event source is also created. In fact, event sources need to be registered on each front-end separately with sufficient permissions, before the logging component can write to the event log using the diagnostic area as the event source. So how would you create the event sources on each front-end? Well, there are a couple of possible approaches:
- Use PowerShell to create the sources on each front-end remotely
- Use a Timer Job to run custom code on each front-end that registers the event source.
In this post, I will show how to do that from PowerShell. These are only two lines of code and the script can be run from a remote location on each front-end.
# First load object models to use
# call the registration method to ensure all registered diagnostic areas are also registered as event sources
In this script, we first load the assembly Microsoft.Practices.SharePoint.Common.dll. We assume here that the assembly is available from the GAC. In my next post, the solution provided will ensure these assemblies are deployed to the GAC for use. Once we have done that, we can call the static EnsureConfiguredAreasRegistered method of the DiagnosticsAreaEventSource class that will iterate through all the configured and registered diagnostic areas and ensures that an event source is registered for that. The event sources will be registered on the Application event log. During the next couple of days, I will also investigate the possibility of registering the sources to different logs.
In the next post, I will show a custom solution on how to create additional diagnostic areas and use a timer job to ensure the event sources are created at the front end. Till next time!