SharePoint 2013 / 2010: Custom ULS Logging provider

Hello, fellow developers!

We often find ourselves in need of a logging solution if we want to develop a reliable and properly monitorable solution, right?
In the multitude of existing 3rd party solutions, like log4net and others it is difficult to make the choice.

But let’s talk about SharePoint!

It has built in logging to that LOGS directory in 14/15 hive, so would not it make sense to tap into that and use this instead of a purely 3rd party solution? I imagine it would do well with ULS Viewer tools, and also performance-wise, as we will use SharePoint internal utilities to log.

This static class will allow you to define your custom categories for logging events, in order for you to be able to easily identify relevant log rows. I also defined two event types there in the enum, feel free to edit. The class uses a static singleton pattern, so usage would be something like this:

 

And here is the code, enjoy:

And that’s pretty much it, your log entries will appear in ULS store. Happy coding!

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *