Monday, December 22, 2014

How to deploy the Provider-Host Sharepoint App to Sharepoint Server 2013


when you complete the development of the Provider host SharePoint,

then you will setup the deployment Configuration by clicking on the Package the app button to build

the app package for deployment.





In the popup window, input the host server url that host your web application. and the application folder

that your app publish to.


the client ID will automatically generated by the visual studio when you build your web project. you can copy
it from the appSettings section in the web.config file.

<add key="ClientId" value="f4c53112-8900-4149-9f6b-8ddb600aeb59" />



How to quickly setup NLog for the Project with Visual Studio

step 1. right click on the project to select the Manage NuGet Package For Solution...
type NLog in the search Box to get the NLog Package.



step 2. after the installation completed. the NLog is automatically the NLog.Config File to the project.
configure the setting in the configuration file. The Trick is that the value of Name attibute in the Target Sections must match with the value of writeTo attribute in the Rules sections.
I already highlighted those two attributes in bold.

 <targets>
    <!-- add your targets here -->
    <target name="ErrorLogs" xsi:type="File" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring,StackTrace:separator=*}${newline}}${newline}" />
   
  </targets>

  <rules>
    <!-- add your logging rules here -->
          <logger name="*" minlevel="Trace" writeTo="ErrorLogs" />
  </rules>

step 3. instantiate the Nlog Object to use in the page or class.

the following snippet of code showing i apply the NLog in the global.ascx object

 private static readonly Logger logger = LogManager.GetLogger(typeof(Global).FullName);

        protected void Application_Error(object sender, EventArgs e)
        {
            logger.Error("Unhandled exception.", Server.GetLastError());
            Server.ClearError();
            Server.Transfer(string.Format("~/Pages/Default.aspx?{0}", TrimQueryString()));
        }