Introducing NLog to SignalR

{  NLog+SignalR+Toastr==NLogToSignalR }

I have created a simple NLog target which uses SignalR (calling it NLogToSignalR) under the covers and delivers the log to either Hub or PersistentConnection and deliver nice messages using toastr.

Where does it fit?



If you use NLog as a logging tool, you can use this to deliver log messages to either same (or remote server) in real time in true toastr style

e.g. Information can be displayed as






How does this work?

You need follow these steps:

1. Put NLog.Targets.SignalR in the same folder as your App.Config/ Web.Config file

2. If you are going to be using Hub for SignalR, use following configuration


3. Deploy the Server NLog.Targets.SignalR.AspNetServer on local IIS.

4. Browse the website after deployment. (Ensure .NET Framework 4.5 is installed)

5. Start logging and watch the logs in real time.

The code is available for download from github.


Web API Fall Update – ODataResult<T>

Another great feature  Web API team has provided support for Server side paging and $inlineCount is called oDataResult<T>

It is really easy to achieve this. Earlier you could return the data but you will have to rely on other mechanisms to achieve $inlineCount.

Step1: Change your return type of the controller action to oDataResult<T>.

Assuming your resource is available at



Step2: Execute the request.


Now you can get the count and a navigation path both.

WebAPI Fall Update 2012 : ResultLimit support on Queryable

In case you have missed this hidden gem from the update, Queryable now supports following four properties. I will cover other properties in separate blog post.

  • ResultLimit
  • StableOrdering
  • LamdaNestingLimit
  • HandleNullPropogation

Having support for ResultLimit is really great news for people using oData support in WebAPI.

This means that you can now set the upper limit on the amount of records that will be returned for a given resource when you apply Queryable attribute. This is very important step to make sure that the client of your API don’t unnecessarily run large queries therby limiting the system scalability.

If you want this capability on an existing system, ensure that oData version of API is latest. Mine is Microsoft.AspNet.WebApi.OData.0.2.0-alpha-121031\lib\net40\System.Web.Http.OData.dll. I have also applied the fall 2012 update.

Let’s say you this method on /webapi/Accounts


and you perform simple Get operation /webapi.


This returns count of 3.

Now add the ResultLimit property on Queryable  Attribute and set this value to 2.


Let’s execute the same query again.


It returns 2 as expected.