public void Log(Type type, string propertyOrMethodSignature, LogLevel sharePointLoggerTraceLevel, string messageFormat, params object[] messageParameters) { // implement this TraceSeverity traceSeverity; EventSeverity eventSeverity; switch (sharePointLoggerTraceLevel) { case LogLevel.Information: traceSeverity = TraceSeverity.Medium; eventSeverity = EventSeverity.Information; break; case LogLevel.Warning: traceSeverity = TraceSeverity.High; eventSeverity = EventSeverity.Warning; break; case LogLevel.Unexpected: traceSeverity = TraceSeverity.Unexpected; eventSeverity = EventSeverity.Warning; break; case LogLevel.Error: traceSeverity = TraceSeverity.High; eventSeverity = EventSeverity.Error; break; case LogLevel.Verbose: default: traceSeverity = TraceSeverity.Verbose; eventSeverity = EventSeverity.Verbose; break; } var category = new SPDiagnosticsCategory(_categoryName, traceSeverity, eventSeverity); SPDiagnosticsService.Local.WriteTrace(101, category, traceSeverity, string.Format(messageFormat, messageParameters), null); }
protected override IEnumerable<SPDiagnosticsArea> ProvideAreas() { SPDiagnosticsCategory defaultCategory = new SPDiagnosticsCategory("MySP2010 Utilities Information", TraceSeverity.Medium, EventSeverity.Information); SPDiagnosticsCategory defaultErrorCategory = new SPDiagnosticsCategory("MySP2010 Utilities Error", TraceSeverity.High, EventSeverity.Error); List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>(); List<SPDiagnosticsCategory> categories = new List<SPDiagnosticsCategory>(); categories.Add(defaultErrorCategory); categories.Add(defaultCategory); areas.Add(new SPDiagnosticsArea("MySP2010 Utilities", categories)); return areas; }
public static void LogDebug(string message) { try { TraceSeverity severity = TraceSeverity.Verbose; SPDiagnosticsCategory category = Local.Areas[LOG_AREA].Categories[UPSClaimProviderLogger.Categories.Debug.ToString()]; Local.WriteTrace(0, category, severity, message); Debug.WriteLine(message); } catch { // Don't want to do anything if logging goes wrong, just ignore and continue } }
private void DoWriteTrace(SPDiagnosticsCategory category, string message, Exception exception) { // Si el level log que vamos a escribir es mayor o igual que el configurado en el web.config, escribe en el destino if (LevelFileLog.ToLower().Equals(ApplicationDirectory.Logging.Disabled)) { return; } if (GetLoggingLevel(GetLoggingLevelByCategory(category.Name)) >= GetLoggingLevel(LevelFileLog)) { Current.WriteTrace(0, category, category.TraceSeverity, ComposeLogMessage(message, exception), null); } }
/// <summary> /// Actually controls the writing. Calls to WriteEvent ALSO writes to the ULS log. That's why the public logging methods /// all use TraceSeverity.None. /// </summary> private void WriteLog(SPDiagnosticsCategory category, TraceSeverity trcSeverity, EventSeverity evtSeverity, string message) { //uint catId = (uint)category; //SPDiagnosticsCategory diagCat = MyLogger.Local.Areas[DiagnosticsAreaName].Categories[catId]; StackTrace stackTrace = new StackTrace(); StackFrame stackFrame = stackTrace.GetFrame(2); MethodBase methodBase = stackFrame.GetMethod(); message = string.Format("{0}.{1} : {2}", methodBase.DeclaringType.Name, methodBase.Name, message); if (evtSeverity != EventSeverity.None) { //Problem - event source might not be registered on Server, and the app pool might not be able to create it. //Therefore, catch the exception, and write it into the logs. Nothing gets written to the Windows log, //but at least it's somewhat handled. try { base.WriteEvent(0, category, evtSeverity, message); } catch (Exception ex) { base.WriteTrace(0, category, TraceSeverity.Unexpected, string.Format("Unable to write to event log {0} : {1}", ex.GetType().ToString(), ex.Message)); // If there was an error writing to the event log, make sure the tracelog is written to instead. switch (evtSeverity) { case EventSeverity.Error: trcSeverity = TraceSeverity.Unexpected; break; case EventSeverity.Warning: trcSeverity = TraceSeverity.Monitorable; break; case EventSeverity.Information: trcSeverity = TraceSeverity.High; break; } } } if (trcSeverity != TraceSeverity.None) { base.WriteTrace(0, category, trcSeverity, message); } }
/// <summary> /// Writes the log. /// </summary> /// <param name="traceSeverity">The trace severity.</param> /// <param name="message">The message.</param> private static void WriteLog(TraceSeverity traceSeverity, string message) { if (traceSeverity != TraceSeverity.None) { try { SPDiagnosticsCategory spDiagnosticsCategory = UnifiedLoggerService.Current.Areas[DiagnosticsAreaName].Categories[Category]; UnifiedLoggerService.Current.WriteTrace((uint)EventId, spDiagnosticsCategory, traceSeverity, message); } catch { } } }
public static void LogInfo(string errorMessage, AIAPortalFeatures category) { try { DiagnosticsService myULS = DiagnosticsService.Local; if (myULS != null) { SPDiagnosticsCategory cat = myULS[category]; string format = errorMessage; //myULS.WriteTrace(1, cat, TraceSeverity.Medium, format, myULS.TypeName); myULS.Information(cat, errorMessage); } } catch {} }
public static void LogMessage(ushort id, string LogCategory, TraceSeverity traceSeverity, string message, object[] data) { try { Logging log = Local; if (log != null) { SPDiagnosticsCategory category = log.Areas[NaupliusDiagnosticArea].Categories[LogCategory]; log.WriteTrace(id, category, traceSeverity, message, data); } } catch (Exception) { } }
private void GetListItems(string str, MenuItem _spMenu, SPList _spListMenu, SPSite thisSite) { AudienceManager audMgr = new AudienceManager(SPServiceContext.GetContext(thisSite)); AudienceCollection audiences = audMgr.Audiences; AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader(); try { SPQuery _spQuery = new SPQuery(); string target = ""; _spQuery.Query = String.Format("<OrderBy><FieldRef Name='LinkOrder' Ascending='True' /><FieldRef Name='Title' Ascending='True' /></OrderBy><Where><And><Eq><FieldRef Name='ParentMenu' LookupId= 'TRUE' /><Value Type='Lookup'>{0}</Value></Eq><Eq><FieldRef Name='ShowMenuItem' /><Value Type='Choice'>Yes</Value></Eq></And></Where>", str); SPListItemCollection _spListItems = _spListMenu.GetItems(_spQuery); MenuItem _spMenuItem = new MenuItem(); foreach (SPListItem item in _spListItems) { target = ""; string audienceFieldValue = (string)item["CanBeSeenBy"]; if (string.IsNullOrEmpty(audienceFieldValue) || AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false)) { if (item["Link URL"] == null) { _spMenuItem = new MenuItem(item["Title"].ToString()); } else { if (_NewWindowFieldExists && item["OpenNewWindow"] != null && (Boolean)item["OpenNewWindow"] == true) { target = "_blank"; } _spMenuItem = new MenuItem(item["Title"].ToString(), "", "", SetServerURL(item["Link URL"].ToString()), target); } GetListItems(item["ID"].ToString(), _spMenuItem, _spListMenu, thisSite); _spMenu.ChildItems.Add(_spMenuItem); } } } catch (Exception ex) { ULSLoggingService myULS = new ULSLoggingService("TopNavProvider", SPContext.Current.Site.WebApplication.Farm); if (myULS != null) { SPDiagnosticsCategory cat = new SPDiagnosticsCategory("CreateChildControls", TraceSeverity.High, EventSeverity.Verbose); cat = myULS[CategoryId.WebPart]; myULS.WriteTrace(1, cat, TraceSeverity.Verbose, String.Format("{0};{1}", ex.Message, ex.StackTrace), myULS.TypeName); } Controls.Add(new LiteralControl(String.Format("An error has occured with this web part. Please contact your system administrator and relay this error message: {0} sub:GetListItems", ex.Message))); } }
public static string LogErrorInULS(string errorMessage, TraceSeverity tsSeverity, Exception errorExecption) { string strExecutionResult = "Message Not Logged in ULS. "; try { SPDiagnosticsCategory category = LoggingService.Current.Areas[vsDiagnosticAreaName].Categories[CategoryName]; LoggingService.Current.WriteTrace(uintEventID, category, tsSeverity, errorMessage + "Exception: " + errorExecption.Message); strExecutionResult = "Message Logged"; } catch (Exception ex) { strExecutionResult += ex.Message; } return(strExecutionResult); }
private SPDiagnosticsCategory GetCategory(string categoryName) { if (string.IsNullOrEmpty(categoryName)) { return(DefaultCategory); } else { SPDiagnosticsCategory foundCategory = FindCategory(categoryName); if (foundCategory == null) { throw new LoggingException(string.Format(CultureInfo.CurrentCulture, Resources.CategoryNotFoundExceptionMessage, categoryName)); } return(foundCategory); } }
/// <summary> /// The write event log. /// </summary> /// <param name="categoryName"> /// The category name. /// </param> /// <param name="eventSeverity"> /// The event severity. /// </param> /// <param name="message"> /// The message. /// </param> private static void WriteEventLog(string categoryName, EventSeverity eventSeverity, string message) { try { UnifiedLoggingServer localService = Local; if (localService != null) { SPDiagnosticsCategory category = localService.Areas[AreaName].Categories[categoryName]; localService.WriteEvent(1, category, eventSeverity, message); } } catch { } }
/// <summary> /// Logs to the ULS. /// </summary> /// <param name="categoryId"></param> /// <param name="traceSeverity">The trace severity.</param> /// <param name="message">The message.</param> /// <param name="args">The message arguments.</param> protected virtual void InnerLog(CategoryId categoryId, TraceSeverity traceSeverity, string message, params object[] args) { //SPSecurity.RunWithElevatedPrivileges( // () => // { if (_innerLogger == null) { _innerLogger = new InnerLogger(Name); } SPDiagnosticsCategory category = _innerLogger.Areas[_innerLogger.Name].Categories[categoryId.ToString()]; _innerLogger.WriteTrace(0, category, traceSeverity, message, args); //}); }
public static string LogErrorInULS(string errorMessage) { string strExecutionResult = "Message Not Logged in ULS. "; try { SPDiagnosticsCategory category = ULSLogger.Current.Areas[vsDiagnosticAreaName].Categories[CategoryName]; ULSLogger.Current.WriteTrace(uintEventID, category, TraceSeverity.Unexpected, errorMessage); strExecutionResult = "Message Logged"; } catch (Exception ex) { strExecutionResult += ex.Message; } return(strExecutionResult); }
private static void WriteLog(LoggerEventType eventType, LoggerOptionsAttribute options, string message) { LoggerTarget targets = options.GetTargets(eventType); if (targets.HasFlag(LoggerTarget.Console)) { ConsoleColor originalColor = Console.ForegroundColor; try { Console.ForegroundColor = GetConsoleColor(eventType); Console.WriteLine(message); } finally { Console.ForegroundColor = originalColor; } } if (targets.HasFlag(LoggerTarget.EntLib)) { try { LogEntry entry = new LogEntry(); entry.Message = message; entry.Priority = 10 - (int)eventType; entry.Severity = GetTraceEventType(eventType); entry.EventId = -1; if (!String.IsNullOrEmpty(options.Category)) { entry.Categories.Add(options.Category); } EntLibLogger.Write(entry); } catch { } } if (targets.HasFlag(LoggerTarget.UlsLog)) { SPDiagnosticsCategory dCat = new SPDiagnosticsCategory(options.Category, GetTraceSeverity(eventType), GetEventSeverity(eventType)); SPDiagnosticsService.Local.WriteTrace(0, dCat, GetTraceSeverity(eventType), message); } if (targets.HasFlag(LoggerTarget.EventLog)) { if (!EventLog.SourceExists(options.Category)) { EventLog.CreateEventSource(options.Category, options.Category); while (!EventLog.SourceExists(options.Category)) { Thread.Sleep(100); } } EventLog.WriteEntry(options.Category, message, GetEventLogEntryType(eventType), 0); } }
/// <summary> /// Write tarce to system's application eventlog. /// If the given value in the severity parameter is less than the currently configured value for /// the category's Event Level property, the trace is not written to the eventlog. /// </summary> public static void WriteEvent(string areaName, string categoryName, EventSeverity eventSeverity, string message) { if (string.IsNullOrEmpty(message)) { return; } try { LoggingService service = Local; if (service != null) { SPDiagnosticsCategory category = service.Areas[areaName].Categories[categoryName]; service.WriteEvent(1, category, eventSeverity, message); } } catch { } }
/// <summary> /// Specifies the message (message) the desired format error message and returns a token /// </summary> /// <param name="message">The simple message text</param> /// <param name="exceptionMessage">Full message text</param> /// <param name="traceSeverity">Specifies the level of trace data that is written to the trace log file.</param> public static Guid WriteError(string message, string exceptionMessage, TraceSeverity traceSeverity) { if (Debugger.IsAttached) { Debugger.Break(); } message = string.Format("SkillWillMessage: {0};", (string.IsNullOrEmpty(message) == false ? message : "Неизвестная ошибка")) + exceptionMessage; SPDiagnosticsCategory category = new SPDiagnosticsCategory(Logger.CATEGORY_ERROR, TraceSeverity.High, EventSeverity.Error); SPDiagnosticsArea area = new SPDiagnosticsArea(Logger.AREA, new SPDiagnosticsCategory[] { category }); SPDiagnosticsService.Local.WriteTrace(0, area.Categories[Logger.CATEGORY_ERROR], traceSeverity, message); return(Logger.GetCurrentCorrelationToken()); }
public static void LogError(UPSBrowserLogger.Categories category, string message) { try { SPDiagnosticsCategory _category = Local.Areas[LOG_AREA].Categories[category.ToString()]; TraceSeverity traceSeverity = TraceSeverity.High; Local.WriteTrace(0, _category, traceSeverity, message); EventSeverity eventSeverity = EventSeverity.Error; Local.WriteEvent(0, _category, eventSeverity, message); Debug.WriteLine(message); } catch { // Don't want to do anything if logging goes wrong, just ignore and continue } }
public void GetDefaultCategorySucceeds() { //Arrange var target = new DiagnosticsService(); MSPFarm.LocalGet = () => new MSPFarm(); var replaceLocator = new ActivatingServiceLocator(); SharePointServiceLocator.ReplaceCurrentServiceLocator(replaceLocator); replaceLocator.RegisterTypeMapping <IConfigManager, MockLoggingConfigMgr>(InstantiationType.AsSingleton); //Act SPDiagnosticsCategory defaultCat = target.DefaultCategory; //Assert Assert.IsTrue(defaultCat.Area.Name == Constants.DefaultAreaName); Assert.IsTrue(defaultCat.Name == Constants.DefaultCategoryName); }
protected SharePointSink( SPDiagnosticsServiceBase diagnosticsService, SPDiagnosticsCategory category, ITextFormatter textFormatter) { if (diagnosticsService == null) { throw new ArgumentNullException("diagnosticsService"); } if (category == null) { throw new ArgumentNullException("category"); } DiagnosticsService = diagnosticsService; Category = category; TextFormatter = textFormatter; }
public void FindCategoryWithMissingCategoryReturnsNull() { //Arrange string testAreaGuid = "{848D873D-EA3C-445A-874A-E80310EC50D4}"; var replaceLocator = new ActivatingServiceLocator(); SharePointServiceLocator.ReplaceCurrentServiceLocator(replaceLocator); replaceLocator.RegisterTypeMapping <IConfigManager, MockConfigManager>(InstantiationType.AsSingleton); replaceLocator.RegisterTypeMapping <IHierarchicalConfig, MockHierarchicalConfig>(InstantiationType.AsSingleton); var target = new DiagnosticsService(); string category11Name = string.Format("{0}/{1}", testAreaGuid, TestsConstants.TestGuidName); //Act SPDiagnosticsCategory category = target.FindCategory(category11Name); // Assert Assert.IsNull(category); }
/// <summary> /// SelectData Method creates a DataTable from the data fetched from SharePoint List or Doc Library and returns the DataTable /// </summary> /// <returns></returns> public DataTable SelectData() { DataTable dataSource = new DataTable(); try { SPSite site = SPContext.Current.Web.Site; SPWeb web = site.OpenWeb(); SPList lstICSSDocuments = web.Lists["PhotoList"]; //create document library or List and add column year,Description,Url,Name, Title is inbuilt. SPQuery query = new SPQuery(); IEnumerable <SPListItem> lstItemICSSDocuments = lstICSSDocuments.GetItems(query).OfType <SPListItem>(); dataSource.Columns.Add("Year"); dataSource.Columns.Add("Description"); dataSource.Columns.Add("Name"); dataSource.Columns.Add("Title"); dataSource.Columns.Add("Url"); SPSecurity.RunWithElevatedPrivileges(delegate() { //SPGroup grpName = web.Groups["ICSSViewers"]; var committeeAndGroupDocumentswithURL = lstItemICSSDocuments.Select(x => new { Year = x["Year"], Description = x["Description"], Name = x["Name"], Title = x["Title"], Url = site.Url + "/" + x.Url }); foreach (var document in committeeAndGroupDocumentswithURL) { DataRow dr = dataSource.NewRow(); dr["Title"] = document.Title; dr["Url"] = document.Url; dr["Name"] = document.Name; dr["Description"] = document.Description; dr["Year"] = document.Year; dataSource.Rows.Add(dr); } }); web.Dispose(); } catch (Exception ex) { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } return(dataSource); }
public void Info(string message, string category, params object[] data) { if (!categories.Contains(category)) { GetType().BaseType.GetField("m_areas", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(this, null); } categories.Add(category); if (string.IsNullOrWhiteSpace(category)) { category = "General"; } SPDiagnosticsCategory diagnosticsCategory = Areas[AreaName].Categories[category]; diagnosticsCategory.EventSeverity = EventSeverity.Information; WriteTrace(0, diagnosticsCategory, TraceSeverity.Monitorable, message, data); }
public static void WriteTrace(String categoryName, TraceSeverity traceSeverity, String message) { if (string.IsNullOrEmpty(message)) { return; } try { WBLogging service = Local; if (service != null) { SPDiagnosticsCategory category = service.Areas[LOGGING_AREA_NAME].Categories[categoryName]; service.WriteTrace(1, category, traceSeverity, message); } } catch { } }
/// <summary> /// n the Page_Load event we are declaring the GridView Object, its event and Datasource /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { txtcreatedBy.Text = SPContext.Current.Web.CurrentUser.Name; txtDate.Text = DateTime.Now.ToString("dd/MM/yyy"); BinData(); } } catch (Exception ex) { //log SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } }
/// <summary> /// /// </summary> /// <param name="ex"></param> /// <returns></returns> public static string LogErrorInULS(Exception ex) { string strExecutionResult = "Message Not Logged in ULS. "; try { string ExceptionMsg = "Source:{0}, Message:{1}, StackTracke:{2}"; string logMsg = string.Format(ExceptionMsg, ex.Source.ToString(), ex.Message.ToString(), ex.StackTrace.ToString()); SPDiagnosticsCategory category = LoggingService.Current.Areas[vsDiagnosticAreaName].Categories[CategoryName]; LoggingService.Current.WriteTrace(uintEventID, category, TraceSeverity.Unexpected, logMsg); strExecutionResult = "Message Logged"; } catch (Exception ex1) { strExecutionResult += ex1.Message; } return(strExecutionResult); }
public static LoggerConfiguration SharePointEvent( this LoggerSinkConfiguration loggerConfiguration, SPDiagnosticsServiceBase diagnosticsService = null, SPDiagnosticsCategory diagnosticsCategory = null, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, string outputTemplate = DefaultTemplate, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) { throw new ArgumentNullException("loggerConfiguration"); } return(loggerConfiguration.Sink( new SharePointEventSink( diagnosticsService ?? SPDiagnosticsService.Local, diagnosticsCategory ?? DefaultCategory, new MessageTemplateTextFormatter(outputTemplate, formatProvider)), restrictedToMinimumLevel)); }
public static void LogActivity(string user, string action, string result, string additionalInfo = "") { try { SPDiagnosticsCategory _category = Local.Areas[LOG_AREA].Categories[UPSBrowserLogger.Categories.ActivityLogging.ToString()]; string initiator = GetCurrentUser(); string message = $"{initiator};{user};{action};{result};{additionalInfo}"; TraceSeverity traceSeverity = TraceSeverity.Medium; Local.WriteTrace(0, _category, traceSeverity, message); EventSeverity eventSeverity = EventSeverity.Information; Local.WriteEvent(0, _category, eventSeverity, message); Debug.WriteLine(message); } catch { // Don't want to do anything if logging goes wrong, just ignore and continue } }
public static void LogError(string errorMessage, AIAPortalFeatures category) { try { DiagnosticsService myULS = DiagnosticsService.Local; if (myULS != null) { //SPDiagnosticsCategory cat = myULS[CategoryId.DocuSignService]; SPDiagnosticsCategory cat = myULS[category]; string format = errorMessage; myULS.WriteTrace(1, cat, TraceSeverity.Unexpected, format, myULS.TypeName); } } catch (Exception) { } //Log(errorMessage, TraceProvider.TraceSeverity.CriticalEvent, category); //SPTraceLogger logger = new SPTraceLogger(); //logger.Write(0, SPTraceLogger.TraceSeverity.Exception,"AIA.Intranet TraceProvider", "AIA.Intranet", category, errorMessage); }
public static void WriteTrace(string categoryName, TraceSeverity traceSeverity, string message) { // NOTE: If the given value in the severity parameter is less than the currently configured value for // the category's TraceSeverity property, the trace is not written to the log. if (string.IsNullOrEmpty(message)) { return; } try { LoggingService service = Local; if (service != null) { SPDiagnosticsCategory category = service.Areas[AreaName].Categories[categoryName]; service.WriteTrace(1, category, traceSeverity, message); } } catch { } }
/// <summary> /// n the Page_Load event we are declaring the GridView Object, its event and Datasource /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { const string DATASOURCEID = "gridDS"; gridDS = new ObjectDataSource(); gridDS.ID = DATASOURCEID; gridDS.SelectMethod = "SelectData"; gridDS.TypeName = this.GetType().AssemblyQualifiedName; gridDS.ObjectCreating += new ObjectDataSourceObjectEventHandler(gridDS_ObjectCreating); this.Controls.Add(gridDS); BindDocuments(); } catch (Exception ex) { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } }
/// <summary> /// Log message to file /// </summary> /// <param name="category">Message category</param> /// <param name="traceseverity">trace severity</param> /// <param name="message">Message to log</param> public static void LogMessageToFile(SPDiagnosticsCategory category, TraceSeverity traceseverity, string message) { var fileName = $"log_pages_{DateTime.Now.ToString("dd_MM_yyyy")}.txt"; var filePath = Path.Combine("c:\\logs", fileName); FileInfo fi = new FileInfo(filePath); if (!fi.Directory.Exists) { System.IO.Directory.CreateDirectory(fi.DirectoryName); } var sw = new StreamWriter(filePath, true); try { var logLine = string.Format("{0:G}: {1} {2} {3}.", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss.ff"), category.Name, traceseverity, message); sw.WriteLine(logLine); } finally { sw.Close(); } }
/// <summary> /// Writes a High level message to the SharePoint ULS only /// </summary> public void High(SPDiagnosticsCategory category, string message) { WriteLog(category, TraceSeverity.High, EventSeverity.None, message); }
/// <summary> /// Writes a Warning to the Windows Event Log, and to the SharePoint ULS logs /// </summary> public void Warning(SPDiagnosticsCategory category, string message) { WriteLog(category, TraceSeverity.None, EventSeverity.Warning, message); }
/// <summary> /// Writes a Medium level message to the SharePoint ULS only /// </summary> public void Medium(SPDiagnosticsCategory category, string message) { WriteLog(category, TraceSeverity.Medium, EventSeverity.None, message); }
/// <summary> /// Writes a Low level message to the SharePoint ULS only (i.e. Most Verbose, or most detailed) /// </summary> public void Low(SPDiagnosticsCategory category, string message) { WriteLog(category, TraceSeverity.Verbose, EventSeverity.None, message); }
/// <summary> /// Writes an Information level entry to the Windows Event Log, and to the SharePoint ULS logs /// </summary> public void Information(SPDiagnosticsCategory category, string message) { WriteLog(category, TraceSeverity.None, EventSeverity.Information, message); }
private void DoWriteTrace(SPDiagnosticsCategory category, string message) { DoWriteTrace(category, message, null); }
public static void WriteTraceStandalone(TraceSeverity severity, string message) { var cat = new SPDiagnosticsCategory("Standalone logging", TraceSeverity.Verbose, EventSeverity.None); var cats = new List<SPDiagnosticsCategory>(); cats.Add(cat); var area = new SPDiagnosticsArea("FedRolesCP", cats); SPDiagnosticsService.Local.WriteTrace(2, cat, severity, message); }
private void LogEvent(string message, int eventId, EventSeverity severity, SPDiagnosticsCategory spCategory) { string formattedMessage = string.Format(CultureInfo.CurrentCulture, "Category: {0}: {1}", spCategory.Name, message); base.WriteEvent((ushort)eventId, spCategory, severity, formattedMessage, null); }
private void DoWriteTrace(SPDiagnosticsCategory category, string message, Exception exception) { // Si el level log que vamos a escribir es mayor o igual que el configurado en el web.config, escribe en el destino if (LevelFileLog.ToLower().Equals(ApplicationDirectory.Logging.Disabled)) { return; } if (GetLoggingLevel(GetLoggingLevelByCategory(category.Name)) >= GetLoggingLevel(LevelFileLog)) Current.WriteTrace(0, category, category.TraceSeverity, ComposeLogMessage(message, exception), null); }