Esempio n. 1
0
        public static void LogActivity(string user, LogActivityActionEnum action, LogActivityResultEnum result, string additionalInfo = "")
        {
            // Log to SharePoint tracing log
            UPSBrowserLogger.LogActivity(user, action.ToString(), result.ToString(), additionalInfo);

            EnsureActivitiesList();
            AddActivityToList(user, action, result, additionalInfo);
        }
Esempio n. 2
0
        static void AddActivityToList(string user, LogActivityActionEnum action, LogActivityResultEnum result, string additionalInfo = "")
        {
            // Add activity info record to the list stored in the session storage so that it will available for display

            /*
             * HttpContext currentContext = HttpContext.Current;
             * if (currentContext == null)
             * {
             *  UPSBrowserLogger.LogError(loggingCategory, "Current HttpContext is null");
             *  return;
             * };
             */
            string currentSiteUrl = SPContext.Current.Site.Url;
            string initiator      = SPContext.Current.Web.CurrentUser.LoginName;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    using (SPSite site = new SPSite(currentSiteUrl))
                        using (SPWeb rootWeb = site.OpenWeb())
                        {
                            rootWeb.AllowUnsafeUpdates = true;

                            SPList list = rootWeb.Lists.TryGetList(ActivityLoggerListTitle);
                            if (list == null)
                            {
                                UPSBrowserLogger.LogError(loggingCategory, $"List '{ActivityLoggerListTitle}' not found in the root web at {currentSiteUrl}");
                                return;
                            }

                            SPListItem item        = list.Items.Add();
                            item["RegisteredDate"] = DateTime.Now;
                            item["Initiator"]      = initiator;
                            item["User"]           = user;
                            item["Action"]         = action.ToString();
                            item["Result"]         = result.ToString();
                            item["AdditionalInfo"] = additionalInfo;
                            item.Update();

                            rootWeb.AllowUnsafeUpdates = false;
                        };
                }
                catch (Exception e)
                {
                    UPSBrowserLogger.LogError(loggingCategory, $"Error adding record to the list list {ActivityLoggerListTitle} in the root web at {currentSiteUrl}. Exception: {e.Message}");
                    return;
                };
            });
        }