Home
Releases
Discussions
Issue Tracker
Source Code
Stats
People
License
RSS RSS Feed
Search Wiki:
A SMS logger to use with the Microsoft Enterprise 2.0 ( and 3.0) library that uses the BT Web21C SDK to send text messages to your phone.



Background

Recently we delivered an ASP.NET 2.0 intranet job application (dare I say it is also a Web 2.0 application). It uses Microsoft Enterprise Library 2.0 including the logging, exception, caching and database blocks.

The logging was great but we had a critical daily function where I wanted to know instantly if it succeeded or failed – wherever I was. Hunting around I found the BT Web21C SDK which gave this useful functionality in one line of code.

The solution was very quick to develop (total 3 hours) as both frameworks make it a simple exercise. Of course it still took me about an hour until I realised I had mistyped the phone number in the configuration file. Someone out there has 10 or so messages – I’m sorry Mr Joe Citizen.

It happily compiles with EntLib 3.0 December CTP as well though I have only production tested with EntLib 2.0.

Here is the configuration screenshot for an example application (obviously with dummy telephone numbers).

Configuration.png

Code Snippets

One line of code for logging:
Logger.Write("This was logged by the EntLib SMS Trace Listener using the BT Web21C Sdk.");


Note: I’m not going describe the steps for creating the custom Trace Listener – just highlight the code that bridges EntLib and BT Web21C.

In the SMSTraceListener class in the Write method. Yes, it is more than one line of code but it could have been a single line!
public override void Write(string message)
{
BT.Sdk.Components.Sms sms = new BT.Sdk.Components.Sms();
sms.Message = message;
string[] recipients = _recipient.Split( 
new string[] { ";" } , StringSplitOptions.RemoveEmptyEntries );
foreach ( string recipient in recipients )
{
sms.AddRecipient(recipient);
}
sms.Sender = _sender;
sms.SendMessage();
}
 


As you can see in the code above, there are two properties, Sender and Recipient, as shown in the SmsTraceListenerData class.

[ConfigurationProperty(recipientProperty , IsRequired=true)]
public string Recipient
{
get { return (string)base[recipientProperty]; }
set { base[recipientProperty] = value; }
}
 
[ConfigurationProperty(senderProperty, IsRequired = true)]
public string Sender
{
get { return (string)base[senderProperty]; }
set { base[senderProperty] = value; }
}
 


Deployment Steps

The basic steps are below. See later for a detailed description
  1. Install BT Web21C SDK http://sdk.bt.com
  2. Install Enterprise Library 2.0 http://www.microsoft.com/downloads/details.aspx?familyid=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en
  3. Install the SMS Trace Listener.
  4. Create an application and configure BT Web21 SDK and EntLib with the SMS Trace Listener (I used the SMSMessage example provided with the BT Web21C SDK ).
  5. Configure the SMS Trace Listener with your sender and recipients.
  6. Start firing out log entries.


What Next?

  • I’m happy to describe how I built the Logger itself though there are mountains of documentation and examples out there in the community.
  • Very tempted to add a Voice Trace Listener using the BT 21C SDK that will connect me with the user who just got a critical error. (Our internal application has the user’s telephone number in their profile).
  • We are looking at Windows Workflow and so will be checking out designing an activity that, you guessed it, sends a text message to the support phone.


Installation

Install BT Web21 SDK

  • I’m not going to repeat the excellent work of Nauman Laghari found athttp://weblogs.asp.net/nleghari/pages/btsdksms.aspx – follow his steps so that you can prove to yourself you can send a text message to your mobile phone. Come back here when you’re done.

Install Enterprise Library 2.0

  • To use the SMS Trace Listener you do not have to understand Enterprise Library – just install it in the default location is best and skip on to the next step but ….
  • If you have not heard of EntLib then take the time to nose around the code and, in particular, take the Logging Hands On Lab. The documentation is excellent and plenty of forums and community groups.

Install the SMS Trace Listener

  • You have the source and the two assemblies in the provided sample. Copy the two assemblies (PH.EnterpriseLibrary.Extensions.Logging. and PH.EnterpriseLibrary.Extensions.Logging.Configuration.Design.dll ) into same directory as the EntLib 2.0 Configuration Manager. If you followed the default installation it will be C:\Program Files\Microsoft Enterprise Library January 2006\bin .

Create the Application

  • To make life easy we’ll use the SMS Message sample application that you already tested successfully that it you send text messages. This should reduce the time for problem resolution first time around. Open it up in Visual Studio 2005.
  • Add a reference to the SMSTraceListener assembly, PH.EnterpriseLibrary.Extensions.Logging.dll. You don’t need to reference PH.EnterpriseLibrary.Extensions.Logging.Configuration.Design.dll – that is just for the Configuration Manager.
  • We need to “EntLib”-enable the application. Easiest done by right-clicking on the app.config file and choosing "Open With" and selecting the EntLib configuration tool. The EntLib hands-on labs show how to do this ..

Configure SMS Trace Listener

  • With the configuration tool open, check that you can add the SMS Trace Listener as in the screenshot below.
ConfigStart.png
  • If you do see the SMS Trace Listener in your list then double-check the step where you installed the SMS Trace Listener. You probably didn’t copy the files to the same directory as the tool.
  • On selection of the SMS Trace Listener you should see a property grid where you can type the sender and recipient numbers ( separated by a semi-colon ‘;’ for multiple ). You will see something like below – but with real telephone numbers I presume.
Note: I have removed the Database Application Block and the default Trace Listeners as it is not required and cluttered up my configuration.

Configuration.png

For those familiar with the Logging framework the rest of the configuration is simple and you can start playing. For everyone else here is a quick step-by-step on completing the configuration.
    1. Right-click the General category under Category Sources and select New Trace Listener Reference.
    2. Select the newly created TraceListener Reference node and select its ReferencedTraceListener property and then, from the drop down list, select SMS Trace Listener.
    3. You should see the configuration like follows:

ConfigurationReference.png


Firing off the SMS Log messages

  • Add a button and put the following one-liner down below. This works as the logger is against the General category and so the category parameter is not required.
Logger.Write("This was logged by the EntLib SMS Trace Listener using the BT Web21 Sdk");





Last edited Jan 27 2007 at 11:59 AM  by PaulHillman, version 8
Comments
san1t1 wrote  Jan 23 2007 at 2:27 PM  
Hey this is great! I've wanted to do this for ages, but always stumbled when it came to choosing an SMS provider. Nice to see BT are exposing services in such a straightforward way.

chila wrote  Aug 26 2007 at 4:25 AM  
Hi Paul, great job. Jsut let me know one thing, are these SMS allowed to be sent worldwide?

Updating...