Monday 13 July 2020

SharePoint Framework - Logging

The logging levels are pre-defined.
 
Logging LevelDefinition
VerboseCorresponds to lengthy events. Logs almost everything.
InformationDoes not require any attention. However, they provide valuable data for monitoring the state of solution.
WarningIndicates potential problem or issue that might need attention. We should monitor the pattern over  time. If ignored, warning may result in sever error.
ErrorRequires urgent attention. All error events should be investigated.
CriticalIndicates serious error that has caused major failure in the solution
NoneNo logging occurs



import ILogHandler from '@microsoft/sp-core-library/lib/log/ILogHandler';
import { ServiceScope } from '@microsoft/sp-core-library';

export enum LogLevel {
  Verbose = 1,
  Info,
  Warning,
  Error
}













import { Log } from '@microsoft/sp-core-library'; 
Define our log source.
const LOG_SOURCE: string = 'SPFxLogger'; 
Log the messages from web part.
@override 
public onInit(): Promise<void> { 
  Log.info(LOG_SOURCE, 'Hello world from SPFx Logger'); 
  Log.info(LOG_SOURCE, JSON.stringify(this.properties, undefined, 2)); 
  Log.info(LOG_SOURCE, `Access the strings as "${strings.BasicGroupName}"`); 
  return Promise.resolve<void>(); 





https://www.c-sharpcorner.com/article/sharepoint-framework-logging/#:~:text=SharePoint%20Framework%20(SPFx)%20also%20has,lifecycle%20of%20the%20web%20part.&text=The%20logging%20levels%20are%20pre%2Ddefined.&text=Corresponds%20to%20lengthy%20events.,Logs%20almost%20everything.