Developer Position

July 24, 2010 00:40 by Deylo
Hi Everyone, I have decided not to pursuit any more private contracts, so I am looking for a full-time position focused more on benefits and continue training. The desired position would allow me to leverage my developer skills with Microsoft .Net technologies. Listed below are some of the technologies that I am currently working with. ASP.net MVC, WPF, WCF, Silverlight, Windows Azure, Azure Storage, MSSQL Server, SQL Azure, Javascripting, REST services, JQuery .... Please let me know of any opportunities. -- Deylo

Azure UTC DateTime converting to local Time Zone.

March 24, 2010 17:40 by Admin

When you create a DateTime object  and store in Azure tables, Azure converts to and stores as UTC.  To retrieve the DateTime object you will get a UTC value the following code will convert back to local time zone, assuming you know what time zone it needs to be converted to.

 

 

        public DateTime ConvertUTCtoLocalTime(DateTime utcDate, string timeZoneId)

        {

            if (timeZoneId.IsNull() || timeZoneId.IsEmpty())

                return utcDate;

 

            TimeZoneInfo localTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);

            DateTime localDate = TimeZoneInfo.ConvertTimeFromUtc(utcDate, localTimeZone);

 

            return localDate;

        }


 

I hope it helps someone.


--
Deylo

How to Log your execptions using Log4net, cool 3rd party API

October 9, 2009 18:45 by Deylo

 

In this blog I would like to show how I usually log my exceptions using a cool free third party control called log4net.  This control is a dll file that can be dropped in the bin folder of the application and with few a configurations in the Web.config file you will be able to write to 3 logging location (system file, event viewer, and in SQL database) and possibly more. 

You can download the log4net API from http://logging.apache.org/log4net/download.html

and it is open source.


After download the zip file you will find the API file log4net.dll here: ..\incubating-log4net-1.2.10\log4net-1.2.10\bin\net\2.0\release

 

Copy the dll to your application bin folder, assuming it is a web application.

You will need to make a reference to the dll from your project.  In Visual Studio right click on references, click add reference navigate to the log4net.dll then click add.  This will make a reference to the log for net APIs.

Now you need configure you web.config file for API to log the your messages to the proper location.

Setting up web.config for SQL server logging

create a table in your SQL database by running this code.

CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1, 1) NOT NULL, [Date] [datetime] NOT NULL, [Thread] [varchar] (255) NOT NULL, [Level] [varchar] (50) NOT NULL, [Logger] [varchar] (255) NOT NULL, [Message] [varchar] (4000) NOT NULL, [Exception] [varchar] (2000) NULL ) 

Now configure you web.config 


in the configuration section add 

  <configSections>
    <sectionGroup ...
   ...
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

little below in the web.config file add the configuration, you can copy and paste and change only the following sections connection string.

<log4net>
<appender name="SQL" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Data Source=127.0.0.1;Initial Catalog=MyDBName;Persist Security Info=True;Integrated Security=True;" />
      <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>

        <!-- Loggers -->
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="SQL"/>
    </root>

    </appender>

Above we entered the configuration for SQL only.

 

You can also add different appenders such as event log and file appenders.  as you can see by adding the following

Setting up web.config for Event Viewer logging

event log appenders: the account running the app needs permission to write to the event log

    <appender name="EventLog" type="log4net.Appender.EventLogAppender" >
      <applicationName value="MyApplication" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>

 

the root node now add event log appender

    <root>
      <level value="DEBUG"/>
      <appender-ref ref="SQL"/>
      <appender-ref ref="EventLog"/>
    </root>

Setting up web.config for file appenders

 

file appenders: the account running the app needs persmission to write to the file where the logs will be entered. 

    <appender name="File" type="log4net.Appender.RollingFileAppender">
      <file value="logs/MyLogFile.log"/>
      <appendToFile value="true"/>
      <rollingStyle value="Composite"/>
      <maxSizeRollBackups value="30"/>
      <maximumFileSize value="10MB"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%-5level] %logger - %message%newline"/>
      </layout>
    </appender>

 


the root node now add file log appender

    <root>
      <level value="DEBUG"/>
      <appender-ref ref="File"/>
      <appender-ref ref="SQL"/>
      <appender-ref ref="EventLog"/>
    </root>

 


The Code to Log

Now that the configuration is completed the code to log is pretty simple, here an example on how I use it.

in you class you add the name space on top of the class

using log4net; 
using log4net.Config;

Create and log to log of type MyClass 

private static readonly ILog log = LogManager.GetLogger(typeof(MyClass))

XmlConfigurator.Configure();


now you can log in different levels by calling any of those methods.

log.Debug("debug message");
log.Error("error message");
log.Info("info message");
log.Warn("warning message");

I hopes this can help you start to log errors and other information in app.  If you need more information you can check out this site http://logging.apache.org/log4net/release/manual/configuration.html

Good luck
--
Deylo

 


Windows Azure Videos - must see.

October 8, 2009 20:12 by Admin

Here are some videos I recommend for windows Azure.

Intro video on Windows Azure

http://videos.visitmix.com/MIX09/T38F

Great start up videos, get you going.

http://msdn.microsoft.com/en-us/azure/dd439432.aspx

First App in Azure with Steve Marx

http://channel9.msdn.com/pdc2008/ES01/

Azure Storage

http://channel9.msdn.com/pdc2008/ES04/

Azure Tables

http://channel9.msdn.com/pdc2008/ES07/

Azure Fabric

http://channel9.msdn.com/pdc2008/ES02/

I hope this helps.  Let me know if anyone has more links.

--
Deylo Woo

 

 


Windows Azure Development Storage Setup for SQL Server 2008

October 8, 2009 19:31 by Admin

When I was planning to install Windows Azure I had SQL Server 2008 installed and I didn't want SQL Express, so I decided to make it work.

Here is what I had to do.

Install Windows Azure SDK and all other components.

Development Storage Setup for SQL 2008:

Go to: C:\Program Files\Windows Azure SDK\v1.0\bin

Change the configuration file for the Development Fabric DevelopmentStorage.exe.config

Change the connectionString setting from:

  <connectionStrings>
    <add name="DevelopmentStorageDbConnectionString"
         connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentStorageDb;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

To

  <connectionStrings>
    <add name="DevelopmentStorageDbConnectionString"
         connectionString="Data Source=localhost\SQL2008;Initial Catalog=DevelopmentStorageDb;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

Also change the developmentStorageConfiguration

  <developmentStorageConfig>
    <services>
      <service name="Blob"
               url="http://127.0.0.1:10000/"/>
      <service name="Queue"
               url="http://127.0.0.1:10001/"/>
      <service name="Table"
               url="http://127.0.0.1:10002/"
                     dbServer=".\SQLExpress"/>

To

  <developmentStorageConfig>
    <services>
      <service name="Blob"
               url="http://127.0.0.1:10000/"/>
      <service name="Queue"
               url="http://127.0.0.1:10001/"/>
      <service name="Table"
               url="http://127.0.0.1:10002/"
                     dbServer="localhost\SQL2008"/>

One more file to change would be the DeveGen.exe.config

from

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="DefaultSQLInstance" value=".\SQLExpress"/>
  </appSettings>
</configuration>

to

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="DefaultSQLInstance" value="localhost\SQL2008"/>
  </appSettings>
</configuration>

 

Save the files, and restart your Development Storage.

Good luck

Deylo Woo