Saturday, January 30, 2016

First Meetup for Year 2016 - Sitecore Habitat - Sitecore User Group Sri Lanka


19th of January 2016, Sitecore User Group Sri Lanka had its first meetup for the year. The topic was about the latest and hotest thing with Sitecore currently, which is Sitecore Habitat.

The topic for the event was "Introduction to Sitecore Habitat Architecture" and the presentation was done by non-other than Mr. Thomas Eldblom, Sr. Technical Manager, GA Field Product Marketing, Sitecore.

event With the help from the Sitecore Community in and out of Sri Lanka, we manage to get the session as our first Live broadcast through OnAir Hangout session.

Recording of the event can be found at our User Group YouTube Channel





Meetup Event : http://www.meetup.com/sugsrilanka/events/227905960/
Facebook Event : https://www.facebook.com/events/1536349779996819/
SitecoreUG.org : http://sitecoreug.org/usergroups/sitecore-user-group-sri-lanka/events/january-meetup-2016/


If anyone interested to learn about Sitecore Habitat, few useful meterias that can be found on internet are shared below.



Few snaps from our meetup session can be found from our Facebook album


Introduction to Sitecore Habitat Architecture by Thomas Eldblom, Sr. Manager, GA Field Product Marketing, Sitecore
Posted by Sitecore User Group Sri Lanka on Saturday, January 30, 2016


Till we meet next time, Happy Sitecore !!!

Saturday, January 23, 2016

Issue with IIS Express Only Starts First Defined Site in applicationhost.config

Today, when I try to visit a website defined in IIS Express, it returned "Unable to connect" error in the browser.

 

But, I had everything configured correctly
1) hosts file entry was added
        127.0.0.1    sc81.local
2) site is defined in applicationhost.config
               <site name="sc81.local" id="3" serverAutoStart="true">
                <application path="/">
                    <virtualDirectory path="/" physicalPath="D:\Sitecore\Prototype\sc81.local\Website" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8070:sc81.local" />
                </bindings>
              </site>

And this is how my <sites> section in the applicationhost.config looks like

         <sites>
             <site name="sc70.local" id="1" serverAutoStart="true">
                <application path="/">
                    <virtualDirectory path="/" physicalPath="D:\Sitecore\Prototype\sc70.local\Website" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8080:sc70.local" />
                </bindings>
              </site>

               <site name="sc81.local" id="3" serverAutoStart="true">
                <application path="/">
                    <virtualDirectory path="/" physicalPath="D:\Sitecore\Prototype\sc81.local\Website" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8070:sc81.local" />
                </bindings>
              </site>
     ....
             <applicationDefaults applicationPool="Clr4IntegratedAppPool" />
             <virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>

After few minutes of struggle, I decide to search this issue on internet. And, I found the answer. :-)

http://stackoverflow.com/questions/7142792/iis-express-7-5-only-loading-one-site-even-though-2-sites-defined

The reason for this is, I just ran the "iisexpress.exe" without "/apppool " parameter.
So, when we just run the "iisexpress.exe", IIS Express will only start the first define site that they can find in the applicationhost.config file.

So, solution for this issue is run the command as follows
iisexpress.exe /apppool:Clr4IntegratedAppPool

You might think, how this is working, since you I don't have specifically define the "applicationPool" setting in anywhere in the configs.

But, if you take a look at the above applicationhost.config file, you see following line, and there we have given the default applicationPool setting.

<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
 
You can also define applicationPool setting in site definition level also as follows

<sites>
             <site name="sc70.local" id="1" serverAutoStart="true">
                <application path="/" applicationPool="customAppPool">
                    <virtualDirectory path="/" physicalPath="D:\Sitecore\Prototype\sc70.local\Website" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8080:sc70.local" />
                </bindings>
              </site>
...







Tuesday, January 12, 2016

Log4net Logging in ASP.NET MVC Application with Autofac IoC Container

In this blog post, I'm trying to discuss log4net logger module integration with ASP.NET MVC application and how it can be integrated with Autofac (an IoC container) to automatic injection of ILog object into Controllers.

Configurations :

  • ASP.NET MVC 5
  • Autofac 3.4.0
  • log4net 2.0.5


Adding log4net into ASP.NET MVC Application


I found following article which discribes the configuration of log4net into ASP.NET MVC application.

http://www.codeproject.com/Articles/823247/How-to-use-Apache-log-net-library-with-ASP-NET-MVC

The steps that included in the above article in short,

Step 1 : Install log4net NuGet package into MyMvcProject.Website
Step 2 : Configure application to use log4net logging configuration by adding to startup.cs file
Step 3 : Add log4net configuration to web.config file
Step 4 : Add logger declaractions to classes which we want to use log4net
Step 5 : Use log.Error to write logging message

In the above "Step 4", we are getting the logger from LogManager.

But, If you are using Autofac as your IoC container for this project, we can do this using Autofac.

Integrating log4net with Autofac


Step 1 : Write Autofac Module

http://docs.autofac.org/en/latest/examples/log4net.html
MyMvcApplication.Website.App_Start.AutofacLoggingModule.cs

Step 2 : Register module into Autofac Config

public static class AutofacConfig {
    public static void ConfigureContainer() {
        var builder = new ContainerBuilder();
        .....
        builder.RegiserModule(new AutofacLoggingModule());
...

Step 3 : Passing ILog into Controller constructor

public class MyController : Controller {
    private readonly log4net.ILog _logger;
    public MyController(ILog logger) {
        _logger = logger;
    }
    public ActionResult MyAction() {
        _logger.Error("Error Message");
    }
}