Spring2 DTG Presentation

Step 2 Performance Test

Using this as a place holder to keep track of my progress

http://www.webpagetest.org/result/100518_341/

with no vendors:

http://www.webpagetest.org/result/100520_22/

Flyleaf, Deafness, Human Trafficking

I thank God for friends with sound music taste.  Otherwise, I’d still be listening to Zeppelin, like it was the only music ever created.

I went to Flyleaf on Friday.  If you’re not familiar with this band, get familiar.  The show was in a word, loud.  Loud enough that for the next two days, I heard I15 traffic in my right ear all day.  This probably was not good, since deafness is genetic in my family as we get old.

While Deafness to me will be a physical reality in 20 or so years, it is also something that plagues our society in general. Lacey brought, in a very powerful and life giving way, attention to the plight of young women who are the victims of Sex Trafficking during the concert.  Often these girls are very young (like children), often sold into slavery by their own families.  I cannot even imagine how that becomes “an option”…  Human trafficking is occurring all over the world today, and sex trafficking is among the most heinous of all.  It is probably going on in your own neighborhood.  You should fight it. Here are some good resources to get involved:

World Vision

Calcutta Mercy Ministries

if you’re in Utah:

UHHR

Operation 61

Operation 61 is putting together a fundraiser 5/10k run this weekend designed to benefit other human trafficking organizations and to reach, rescue and restore women and men locally, and around the world.  I really encourage you to participate.

Grace and Peace,

Parsnips

Return to Log4Net Hell

Do you know what my favorite quote from the log4net faq website is?

Is log4net a reliable logging system?

No. log4net is not reliable.

Ah yes, welcome back to hell!  I remember growing up watching one of the “Road Films”, with Bing Crosby and Bob Hope, where they were dealing with a Voodoo Witch Doctor.  Fast forward to today and it’s like the authors of the Log4Net logging framework took inspiration from the movie. I wouldn’t be surprised if there is a special dance you have to do, or sacrifice to some 486 in an office somewhere to get this thing working correctly.

So I come into the office this morning to “logging’s not working and we’re configuring it correctly”… I figured about half of that statement was true, and went to verify that loggng still worked on my local machine, and I would verify it was working on the staging environment.  After all, everything was working well on Friday.  Right??  Did the temperature suddenly get very hot?  After bit of cussing, I found this gem:

When should I log my first message?

The simple answer is as soon as possible. The long answer is more complex.

If you are configuring log4net programmatically, i.e. by calling the XmlConfigurator.Configure method then you should do so before you begin logging and it is reasonable to do this very soon after application start.

If you are configuring log4net by specifying assembly level attributes on your assembly then the configuration will be loaded once the first call to theLogManager.GetLogger is made. It is necessary that the first call to LogManager.GetLogger made during the process (or AppDomain) is made from the assembly that has the configuration attributes. Log4net will look only once and only on the first calling assembly for the configuration attributes.

Well that just makes perfect sense, right?  Whatever assembly happens to log first, that’s the configuration everyone is going to use.  I’m not going to bother asking why the guys felt that including configuration via assembly attribute was necessary, or even desired if this is the behavior.  So remember this little slice of code?

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

Yeah that was fairly worthless.

So what I had to do, was create a global.asax which would make the appropriate calls for log4net to be configured correctly on the startup of my application:

protected static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    void Application_Start(object sender, EventArgs e)
    {
        String currentWebRootFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
        String api4netConfigPath = System.IO.Path.Combine(currentWebRootFilePath, "log4net.config");
        log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(api4netConfigPath));
        log.Info("Starting " + System.Reflection.Assembly.GetExecutingAssembly().FullName);
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        log.Info("Stopping " + System.Reflection.Assembly.GetExecutingAssembly().FullName);
    }

After testing and verifying it worked… again, I checked it in.  I’m fully expecting to write a third post in this series, so stay tuned.

Parsnips

Doctrine Book Reviews

There are few things you can do in life, which will both at once waste time, and enrich it. Reading is one of those things. I could spend every waking hour nose in book, if money were no object. I have particularly great joy when reading books on Christianity.  For example, in a matter of hours I read C.S. Lewis’ Screwtape Letters.. and then immediately re-read the whole book.  I love to discover what various authors have taken from the Bible, and then study the scripture with their thoughts fresh in memory. Recently, I’ve taken to reading quite a bit of material on Christian Doctrine. I find that the more I investigate who God is,my appreciation for how God uses events in my own life increases dramatically. I started off with Wayne Grudem’s basic primer Christian Beliefs, which deals with foundational topics that all Christians should know about.  Topics like “Election”, “Sanctification” , and “Justification”. All very “Christianese” terms about God’s love for us, and what it means to be given unmerited favor, and the power that God uses to change peoples hearts from stone to flesh.

Another book I’ve read, that I highly recommend is Spectacular Sins by the incredibly famous theologian/pastor John Piper.  The premise of Piper’s book is that Jesus is in charge of everything, that all things are created for him.

He is the image of the invisible God, the firstborn of all creation.  For by him all things were created in heaven and on earth, visible and invisible, whether thrones or dominions or rulers or authorities – all things ewer created through him and for him.  Colossians 1:15-16

Among the powers and principalities referred to by the Apostle Paul include the spiritual enemies that encroach on our lives, and are fighting against God in a cosmic battle, they are destined to lose while bringing Jesus all the Glory in the Process! The book examines some of the greatest sins committed by men against God and shows how God uses them for his purpose (Romans 8:28).  My favorite example he uses was by Joseph, who meeting his brothers who sold him into slavery. Knowing his brothers had great fear of his retribution, Joseph reassured them:

Joseph said to his brothers, “Come near to me, please.” And they came near. And he said, “I am your brother, Joseph,whom you sold into Egypt. And now do not be distressed or angry with yourselves because you sold me here, for God sent me before you to preserve life. For the famine has been in the land these two years, and there are yet five years in which there will be neither plowing nor harvest. And God sent me before you to preserve for you a remnant on earth, and to keep alive for you many survivors. So it was not you who sent me here, but God. Genesis 45:4-8

What an amazing statement of forgiveness of guys who only sold him into slavery because killing him would have made their oldest brother guilty in conscience.

The latest book on Doctrine I picked up is Mark Driscoll’s and Gerry Beshear’s Doctrine – What Christians Should Believe. I found this book at Barnes and Noble, totally on accident.  I knew that Mark was involved in a book project, and when I saw it on the shelf, I made yet another impulse buy (the first of the day being a Macbook Pro).  I sat down with a peppermint tea, expecting to get through maybe 20 or 30 pages.  76 pages and two chapters later, I was raving about it on social media.  These guys hold nothing back at all.  Chapter 1 is titled Trinity: God Is. A bold, and true exposition of who God is (Love by the way), and his makeup.  Not only that, but explaining why that is important, in very practical terms.  These guys pack a ton of great information, in a very readable format.  My favorite section so far, is actually in Chapter 1, which talks about the first appearence of our Trinitarian God, right from Genesis 1:1.  When the ancient Jewish Rabbi’s were translating Genesis into Aramaic, they did a word study on the Hebrew word re’shit which is used as a replacement for the Hebrew word for “firstborn” (bekor) Several times in the Old Testament.  What was even more tripped out, was 200 years before Christ’s arrival, these Rabbi’s (in the Targum Neofiti) rendered Genesis 1:1,2 with both words, in English being

In the beginning, by the firstborn, God created the heavens and the earth.  The earth was without form and void, and darkness was over the face of the deep.  And the Spirit of God was hovering over the face of the waters.

As a Christian, I’ve found my life greatly enriched by not only reading these books, but being able to share the ideas with others.  Knowing the Doctrine’s that make up your faith will equip you to help your friends go to the right source of knowledge, and to grow closer to God.

Parsnips


Log4Net Hell

Like Dante, I’ve seen hell. Hell takes many forms depending on the sin. My sin was not knowing how to configure the ADONetAppender in log4net. The “Good News” I bring to you is how to avoid going to Log4Net hell.

First of all, if you’re having trouble with log4net, stop whatever you were doing. Go outside and take a few deep breaths. Come back to computer, and in your Web.config (or App.config) put the following lines in the configuration node:


	
    

    


		
	    
	
    

*Note* You’ll want to remove these Web.config/App.config lines when your code is running in production *Note*

The next thing is to make sure the Assembly you’re interested in logging from, knows where to find the config file… Put this in the AssemblyInfo.cs file, for the assembly:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

Ok, now everything should work, right? WRONG! You’re in Hell, remember? Your log4net.config file, should be placed in the path that is being executed. Ok, what does that mean? I’ll give an example with a wcf file structure:

webapp
   someservice.svc
   log4net.config <——–log4net.config should live here
   web.config
   bin
      somedll.dll <——-Not in here

Now restart your application, and trigger a log event. You’ll see the file C:\temp\log4net.txt existing. Great. Open that file and look at it. It has all the information you need to stop pulling out your hair, banging on your desk, cussing, and any real sin you may be inclined to do.

Hopefully these simple steps keep you out of Log4Net hell.

Bug Fixing

Sometimes I see really stupid code, and get afraid to fix it:

public void ChangeOrderUser(IdType userId, IdType firmLocationId) {
	    if (data.UserId.Equals(userId)) {
		return;
	    }
	    if (CurrentUser.DefaultAnonymousUser.IsTrue || CurrentUser.DefaultAnonymousUser.IsFalse) {
		if (data.OrderStatus.Equals(OrderStatusEnum.NEW)) {
		    data.UserId = userId;
		    data.OrderDelivery.FirmLocationId = firmLocationId;
		    this.Update(data);
		} else {
		    throw new Seamless.Manhattan.Exceptions.InvalidStateException("Order is not new");
		}
	    } else {
		throw new System.Security.SecurityException("Current Owner is not the Default Anonymous User");
	    }
	}

Can you spot it?

PostSharp and WCF Exception Handling

Just read an interesting article talking about WCF exception handling. I was already planning on doing something similar with the REST Starter Kit. I’ll post some code soon.

Parsnips

Post Sharp

How many times have you found yourself doing something like the following?

public void foo() {
   ValidateUserCanUseFunction();
   //Do more stuff
}

or

public void foo(obj[] args) {
   LogABunchOfStuff(args)
   //Do more stuff
}

In my day job, such code is the rule, rather than the exception. In my gigs, I love using Python. One of the things that is nice about Python is the ability to define method “decorators” which can inject functionality into another function. If you’re familiar with Django Authentication framework, for example, you’ve probably made use of the nice @login_required decorator.

I found myself wishing C# had this Python-esque behavior. Turns out, something very very cool is available: PostSharp.

In my current project, I want to be able to log all accesses to methods, and their parameters… No problem. Simply write an Attribute class that implements some of the AOP library from PostSharp, and then do things like

[Audit] //<--- Neat
public class Foo {
   //Methods and Members
}

Or when you need to make sure that user of the method passed in a valid object

public class Foo {

   [PhoneNumber] //<--- Make sure that is a phone number homey.
   public String _somePhoneNumber{
     get;
     set;
   }
}

My next project with it, is to show how it can be applied to Maverick to do Auth just like Django's auth stuff is done.

Michael Parsons LinkedIn Profile

I almost never use LinkedIn… But I’m there too.

Michael Parsons – LinkedIn

Boo Yah.