My Software Notes

Useful things I discover

Archive for January 2013

log4net – Quick and Dirty set up

leave a comment »

I do this infrequently enought that I have to keep going back to old projects to see the steps.  So, I’m putting them here to save me the hunting.

  1. Use NuGet to pull in the Log4Net binaries, etc. to your project.
  2. Add to your web.config <configSections> element:
    <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
  3. Add to your web.config under the root <configuration> element (modify the appender as you wish):
      <log4net threshold="All">
        <appender name="LogFile" type="log4net.Appender.FileAppender" >
          <file value="c:\logs\MyLog.log" />
          <appendToFile value="true" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date %-5level %-40logger{2} - %message%newline" />
          </layout>
        </appender>
    
        <root>
          <level value="All" />
          <appender-ref ref="LogFile" />
        </root>
      </log4net>
  4. Add to your AssemblyInfo.cs file:
    [assembly: log4net.Config.XmlConfigurator(Watch = true)]
  5. In the file where you want to use it:
    using log4net;
  6. Example of use:
    var log = LogManager.GetLogger(System.Reflection.MethodBase
        .GetCurrentMethod().DeclaringType);
    log.Error("This is a test log message with an exception", 
        new Exception("Test Exception"));

That should do it.

Examples of config: log4net Config Examples

Advertisements

Written by gsdwriter

January 31, 2013 at 1:07 pm

Posted in .NET, Logging, Tools

Windows 8 in 4 or 24 minutes

leave a comment »

Two videos by Scott Hanselman to get someone up and running on Windows 8.  The first video takes 4 minutes and if you blink you’ll miss something important.  I rate it “R” for “Really Geeky”.  The second video takes 24 minutes and I rate it “PG” for “Parents and Grandparents”, because they’ll be able to follow it.

Video 1: Learn Windows 8 in 3 Minutes (Ok it’s really 4)

.

Video 2: The Missing Windows 8 Instructional Video – Who moved my Windows 8 Cheese?

Hope they help.

Written by gsdwriter

January 14, 2013 at 12:31 pm

Posted in Windows 8

CRM 2011 – Ajax call using jQuery returns “No Transport” error

with 2 comments

I was trying to call the OData service in CRM.  I was using the good old jQuery $.getJSON function.  It was failing with the “errorThrown”  parameter telling me “No Transport”.

I had a vague recollection of hitting this error in a different context last year, so I looked it up and found that the error can be caused by a cross-domain Ajax request.

For Example:

Your browser url is “http://crm/MyCorp” and your Ajax call uses http://server03/.

Gotcha

On the surface, this didn’t really explain my problem.  My browser was pointing at my CRM installation and I was making a call to the OData service on the same installation.  So why the cross domain issue?

Then it hit me.  There were two ways to get to the CRM installation.  There was a DNS entry for “crm” and there was one for the server itself called “crmserver03”.  I checked what url was being used by running the JavaScript debugger (good old F12) and there was the answer:  My browser was pointing at http://crm/MyCorp and the Ajax call was going to http://crmserver03/MyCorp.  Huh?

I hunted a bit more and here is what I found:  I was using the Xrm.Page.context.getServerUrl function to make sure I had the right server url BUT this function does not return the domain the browser is using.  Instead it returns the domain that was set in the config of the CRM installation.

See:  How does “Xrm.Page.context.getServerUrl” work?

So if you navigated to the CRM installation using the domain name “crm” and the config says “crmserver03”, then calling getServerUrl will return a different domain to the one your browser is using.  In this case, if you use getServerUrl to build the URL for an Ajax call then you will be using a different domain name and will get the “No Transport” error (unless you’ve done this: How to make a cross-domain Ajax call in jQuery).

I think that’s a bug in gerServerUrl.

Anyway.  Here is my fix:

var url = window.location.protocol +  "//" +  
    window.location.host + "/" + 
    Xrm.Page.context.getOrgUniqueName();

Or, for a relative url, you can use:

var url = "/" + Xrm.Page.context.getOrgUniqueName();

Whichever suits your needs.

Update: See comment below from Carsten Groth and my reply for a new Xrm function that returns the correct url.

Written by gsdwriter

January 7, 2013 at 1:48 pm