Monthly Archives: September 2014

Amazon S3 Sink for Semantic Logging Service – Enterprise Library

Event Source API was introduced in .net framework 4.5 to support semantic logs. It allows an application to author events. These events are generated as ETW events which can be consumed in-proc or out-proc. For a general in-proc consumption, the API has introduced EventSourceListener type.

Semantic Logging Application Block (SLAB) has developed on top of EventSource API with more focus on event’s consumption. It has introduced sinks for consumption which are utilized by ETW event listener in the application block. These events are destination specific. The Pattern & Practices (p&p) team, at Microsoft, has also provided some example sinks. They are for destinations including console, text file (including rolling files), sql server and Windows Azure Table Storage.

The API also allows custom sinks. We can create these sinks for our custom sinks and plug it with Semantic Logging Service for out-proc consumption. In this post, we are going to create a sink for Amazon Simple Storage Service i.e. S3. We would assume a text file in a specified s3 bucket. During instantiation we would be reading contents of this file. We would continue to add on this content. When the service shuts down, we should be uploading the new contents to the same file. Isn’t that easy?


If you don’t already have AWS SDK for .net yet, download and install it from here []. It provides the necessary project templates to create S3 C# project used in this post. Here we are using Empty Project template for Amazon S3.


The extension opens up a dialog next asking about user credentials. Here you can add the credentials for your AWS account. It should be adding the following keys in application configuration file. You can delete them from here as the service wouldn’t be using the configuration from the assembly.

Here we are adding the assembly name and default namespace for the types in the assembly. Let’s add a new folder Sinks for holding the sink type. You can verify that the template has already added the required assembly for AWSSDK.


Now we need to add the nuget package for Semantic Logging Application Block. Make sure that you use the nuget package with the same version used by the Semantic Logging Service used in your environment. This is to avoid the assembly conflicts.


Now we can add the sink definition to the project. Here we are adding it to the Sink folder. As it is apparent, all sinks must inherit from IObserver<EventEntry>. Here we are picking up the bucket and file names from the app config. In this simple implementation we are reading the contents of the file. We keep appending to the contents. When the service shuts down, we are uploading the updated contents to the same file in S3 bucket. You would definitely have a little more details required to be logged in your environment.

Now build the assembly. We can copy the assembly to the semantic logging service folder. Please don’t forget to copy AWSSDK.dll assembly as well.


We also need to update the exe config for the semantic logging service (SemanticLogging-svc.exe.config) with the following app settings:

Now we just need to update SemanticLogging-svc.xml and use the above sink. Here we can simply use customSink element.

Get the code from GitHub


Android Development – Supporting Toast & Vibrations

This is continuation of our post for android app development for viewing GitHub contributions for a user. As we have been going along this path we have been adding different features to the app learning the details about the development of the feature in consideration. In this post we are going to add toast notifications and vibrations when our android device is connected / disconnected from the network.


Toasts are also notification messages which are shown to the user for a limited time. They are mostly status updates with minimum UI. Generally we just set the message and show it but we can also customize the view keeping them close to the theme of our app.

The toast would be displayed when the application is up and running and suddenly there is a disconnect from the network. The toast message should provide the details about the disconnect.


A toast can be displayed for a long or short duration. Unfortunately there are only two constant values which can be specified. They are Toast.LONG_DURATION and Toast.SHORT_DURATION. They have values of 1 and 0 respectively. Now what would be the actual duration when we specify one of these values? For Toast.LONG_DURATION, the actual time this message would continue to be displayed is 3500ms (3.5 seconds). For Toast.SHORT_DURATION it is 2000ms (2 seconds).

We can also customize the display of the toast notification using setView method. It accepts android.view.View as argument.

Vibrating Android Device

As you know Android devices also supports vibrations. It supports vibrating a device for a limited duration or indefinitely. It also supports patterns for vibrations where a device is vibrated including various delays in between.

In order to access the vibration service, we need to add the required permission requirement in AndroidManifest.xml as follows:

Below we are using Android API to get Vibrator Service. We are checking if android service is available for our app plus device supports vibrating. We are then vibrating the device for a certain duration (500 ms).

An Android emulator doesn’t supports vibrating the virtual device. Now how can we test if the vibration code is working. Actually we can just have a look at the LogCat messages. Here it shows the vibrating service being used.


Download Code