Write to ULS Logs Programmatically in SharePoint 2013/SharePoint 2010 On Premise

This is in continuation with blog I posted on “ULS logs in SharePoint 2013/SharePoint 2010 on premise

Here I would provide approach to write to ULS logs programmatically. User needs to have basic knowledge on how to open Visual Studio 2010/2012/2013 and should have basic knowledge on how to write a class.

To start with we will create a class in Visual Studio, need to paste following code to class(please make formatting changes).

//Class Starts

———————————————————————————————-

using System.Collections.Generic;
using Microsoft.SharePoint.Administration;

namespace SampleLogger.ULSLog
{
public class SampleLogger : SPDiagnosticsServiceBase
{
private const string PName= “Sample Log “;

private static SampleLogger  logger;

 private SampleLogger() : base(PRODUCTNAME + “ULS Logging Service”,            SPFarm.Local)
{}

/// <summary>
/// Here we create Log Instance
/// </summary>
private static SampleLogger loggerInstance
{
get
{
if ( samplelogger != null) return samplelogger;
else return samplelogger = new SampleLogger();
}
}

/// <summary>
/// Options to specify different Log Category under which logs will be    classified in ULS log
/// </summary>
/// <returns></returns>
protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
{
var diagnosticsCategories = new List<SPDiagnosticsCategory>
{

//One can add more categories as per requirement
new SPDiagnosticsCategory(LogCategory.ApplicationPages.ToString(),               TraceSeverity.Unexpected, EventSeverity.Error),
new SPDiagnosticsCategory(“SampleLogger Details”,                                                 TraceSeverity.Monitorable, EventSeverity.Information)
};
var areas = new List<SPDiagnosticsArea>
{
new SPDiagnosticsArea(PName, diagnosticsCategories)
};

return areas;
}

/// <summary>
/// Follwoing creates Trace Entry
/// </summary>
/// <param name=”methodName”>Method Name Object</param>
/// <param name=”traceMessage”>Log Message</param>
 public static void WritetoULS(string methodName, string traceMessage)
{
SPDiagnosticsCategory category =                                                                                    loggerInstance.Areas[PName].Categories[“SampleLogger Details”];
loggerInstance.WriteTrace(0, category, TraceSeverity.Monitorable, PName+ ” Custom::” + methodName + “::” + traceMessage);
}
}
}

———————————————————————————————-

//Class ends

Now Call the class from other location(webpart.cs, usercontrol.cs, event receivers, other class.cs) etc to use and write to ULS logs

SampleLogger.ULSLog.WritetoULS(“Your Sample details here”, “Anyother info you feel needs to be written”);

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

ULS logs in SharePoint 2013/SharePoint 2010 on premise

ULS (Trace) Logs in SharePoint 2013/SharePoint 2010 on premise

Here I would explain details on how to write to ULS logs using code behind (this will be covered in next post), also I would focus on how to change ULS logs file path. This all implies for SharePoint on premise and not for SharePoint Online.

First let’s start with where ULS logs are stored by default on server and how to change the default path.

Following are details for SharePoint 2010

To find ULS logs path on server, need to go to

Central Admin -> Monitoring -> Configure Diagnostic Logging under Reporting

configureULS

Click on Configure Diagnostic Logging will take us to Log Details page from where we can check path for ULS(Trace) logs.

ULSPath

Default path is (14 Hive): C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

From here we can change path if we wish to store ULS logs to different location else it will be stored at above location on server.

Similar Details we have for SharePoint 2013, there is no change but for your reference I would add Screenshots here.

To find ULS logs path on server, need to go to

Central Admin -> Monitoring -> Configure Diagnostic Logging under Reporting(Same as SharePoint 2010).

SP2013

Click on Configure Diagnostic Logging will take us to Log Details page from where we can check path for ULS(Trace) logs.

Here I have changed default path(15 Hive) to point to other path on server.

SP2013Path

Other details can be configured are

  • Number of days to store logs files
  • Restrict Trace log

This includes details on how to view ULS log files from server and also how to modify default location for ULS logs, next article would focus on how to write custom message to ULS logs.

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

Create new site in SharePoint 2010/SharePoint 2013

Here I would explain details on how to create a SharePoint subsite in SharePoint 2010 and SharePoint 2013. We would do it using SharePoint out of box options, later in this blog I would explain details on how to create site programmatically using PowerShell Commands.

Create new site in SharePoint 2010:

To create a site in SharePoint 2010, need to open sample site.

e.g. http://contoso.com/

now go to Site Actions -> New site(Need to make sure you have site Admin rights)

New Site

on click of New Site will open following page to select templates.

create

Select required template based on your need, supply name and site URL suffix that will appear as http://contoso.com/yoursitename and click on Create.

This will create a new site under contoso.com with specified template.

Create new site in SharePoint 2013:

To create a site in SharePoint 2013, need to open sample site.

e.g. http://contoso.com/

now go to Top Right Gear Icon -> Site contents(Need to make sure you have site Admin rights)

New Site SharePoint 2013

This will take you to Site Content Page, which will look as sample shown below.

SiteContents

Now click on New Subsite this will open following Page. Specify Name, Site URL, Template and Permission if need to inherit from parent site.

NewSitePage

Once we have specified above fields, click on Create, this will create a new site for us in SharePoint 2013.

Create site using PowerShell Commands:

We can use following PowerShell commands to create a subsite.

New-SPWeb –url <new site url> -name <new site name> -template <template name>

Example:

New-SPWeb –url http://contoso.com/sampleSite -name “sample Site”-template STS#0 –AddToTopNav –UniquePermissions –UseParentTopNav

More Site templates code can be viewed from following references.

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

SharePoint 2013 App model overview

What is SharePoint App model?

We are familiar with Smartphone/Tab Apps, similar concept is implemented in SharePoint 2013 apps for Web. One can view SharePoint out of box installed apps from Site Actions (top right gear icon) -> Site Content. This will show pre-installed apps (point to note, now Lists and Libraries are classified under SharePoint 2013 apps)

SiteContent

Development Options in SharePoint 2013:

We as a developer know, there are 3 different development options available in SharePoint 2013.

  1. SharePoint Full Trust Solution – Uses server side object model and Client side object model.
  2. SharePoint Sandbox Solution – This was available in 2010, but not available in 2013, uses both client side and server side object model, and doesn’t have full trust.
  3. SharePoint Apps – Only uses client side object model.

Following is pictorial representation of 3 different approaches.

Compare

When to go for SharePoint 2013 App

We can choose to go for SharePoint app when we decide usage of Client Side Object Model (CSOM) and we don’t need full trust solution that uses Server Side Object Model (SSOM). Decision will solely depend on usage of CSOM vs SSOM.

CSOM

Once we have decided to go for SharePoint Apps, we can choose which App to create based on Hosting Options.

There are two hosting options for SharePoint Apps

  • SharePoint Hosted Apps
  • Cloud Hosted Apps – This has two sub options
    1. Auto Hosted App
    2. Provider Hosted App

Hosting

Once we have decided App Hosting, we can now confirm based on App Shape, what would be our final App. Following are 3 classification based on App Shape.

  • Full Page
  • App Parts (Client webpart)
  • UI Commands (Extended Ribbon, Extended Menu)

More Info:

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

Create document library with Content Types in SharePoint 2010/2013

To create new document library with defined content types please follow these steps:

Step 1: Open the site http://Contoso.com/(your SharePoint site)

Step 2: Go to Site Actions -> View All Site Contents -> Click on Create Icon

Create

Step 3: This will open following popup, select Document Library and Specify Name to it.

DL

Step 4: Click on Create will create a document library with Specified name.

Step 5: Now go to Document library (Site Actions -> View All site Content -> Click on the document library name)

Step 6: Click on Library Settings

LS

Step 7: Click on Advance Settings

AS

Step 8: Select option Allow management of content type “Yes” and click on ok button

CT

Step 9 : Now, it will land to Library Settings Page with Content types enabled.

Step 10 : Click on “Add from existing site content types”

Step 11 : This will open following screen, add required document Content types and click on OK.

Content

Step 12: This will complete Document Library creation with added content types.

PS: Example is given for SharePoint 2010, similar way one can create Document Library in SharePoint 2013.

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania