How to change the Workflow History list programmatically?

    1: SPSite spSite = new SPSite("https://localhost");
    2: SPWeb spWeb = spSite.OpenWeb();
    3: SPList spList = spWeb.Lists["Shared Documents"];
    4: SPList workflowlist = spWeb.Lists["NewHistoryLibary"];
    5: SPWorkflowAssociation association = spList.WorkflowAssociations[0];
    6: association.SetHistoryList(workflowlist);
    7: spList.UpdateWorkflowAssociation(association);