Esempio n. 1
0
        /// <summary>
        /// Adds a log item to the log immidiately instead of Queuing it as a work item.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="comment">The comment.</param>
        public static void AddSynced(LogTypes type, int userId, int nodeId, string comment)
        {
            var logTypeIsAuditType = type.GetType().GetField(type.ToString()).GetCustomAttributes(typeof(AuditTrailLogItem), true).Length != 0;

            if (logTypeIsAuditType)
            {
                try
                {
                    SqlHelper.ExecuteNonQuery(
                        "insert into umbracoLog (userId, nodeId, logHeader, logComment) values (@userId, @nodeId, @logHeader, @comment)",
                        SqlHelper.CreateParameter("@userId", userId),
                        SqlHelper.CreateParameter("@nodeId", nodeId),
                        SqlHelper.CreateParameter("@logHeader", type.ToString()),
                        SqlHelper.CreateParameter("@comment", comment));
                }
                catch (Exception e)
                {
                    LogHelper.Error <Log>("An error occurred adding an audit trail log to the umbracoLog table", e);
                }

                //Because 'Custom' log types are also Audit trail (for some wacky reason) but we also want these logged normally so we have to check for this:
                if (type != LogTypes.Custom)
                {
                    return;
                }
            }

            //if we've made it this far it means that the log type is not an audit trail log or is a custom log.
            LogHelper.Info <Log>(
                "Redirected log call (please use Umbraco.Core.Logging.LogHelper instead of umbraco.BusinessLogic.Log) | Type: {0} | User: {1} | NodeId: {2} | Comment: {3}",
                () => type.ToString(), () => userId, () => nodeId.ToString(CultureInfo.InvariantCulture), () => comment);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the specified log item to the log.
        /// </summary>
        /// <param name="type">The log type.</param>
        /// <param name="user">The user adding the item.</param>
        /// <param name="nodeId">The affected node id.</param>
        /// <param name="comment">Comment.</param>
        public static void Add(LogTypes type, User user, int nodeId, string comment)
        {
            if (Instance.ExternalLogger != null)
            {
                Instance.ExternalLogger.Add(type, user, nodeId, comment);

                // Audit trail too?
                if (!UmbracoSettings.ExternalLoggerLogAuditTrail && type.GetType().GetField(type.ToString()).GetCustomAttributes(typeof(AuditTrailLogItem), true) != null)
                {
                    AddLocally(type, user, nodeId, comment);
                }
            }
            else
            {
                if (!UmbracoSettings.EnableLogging) return;

                if (UmbracoSettings.DisabledLogTypes != null &&
                    UmbracoSettings.DisabledLogTypes.SelectSingleNode(String.Format("//logTypeAlias [. = '{0}']", type.ToString().ToLower())) == null)
                {

                    if (comment.Length > 3999)
                        comment = comment.Substring(0, 3955) + "...";

                    if (UmbracoSettings.EnableAsyncLogging)
                    {
                        ThreadPool.QueueUserWorkItem(
                            delegate { AddSynced(type, user == null ? 0 : user.Id, nodeId, comment); });
                        return;
                    }

                    AddSynced(type, user == null ? 0 : user.Id, nodeId, comment);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the specified log item to the log.
        /// </summary>
        /// <param name="type">The log type.</param>
        /// <param name="user">The user adding the item.</param>
        /// <param name="nodeId">The affected node id.</param>
        /// <param name="comment">Comment.</param>
        public static void Add(LogTypes type, User user, int nodeId, string comment)
        {
            if (Instance.ExternalLogger != null)
            {
                Instance.ExternalLogger.Add(type, user, nodeId, comment);

                // Audit trail too?
                if (!UmbracoSettings.ExternalLoggerLogAuditTrail && type.GetType().GetField(type.ToString()).GetCustomAttributes(typeof(AuditTrailLogItem), true) != null)
                {
                    AddLocally(type, user, nodeId, comment);
                }
            }
            else
            {
                if (!UmbracoSettings.EnableLogging)
                {
                    return;
                }

                if (UmbracoSettings.DisabledLogTypes != null &&
                    UmbracoSettings.DisabledLogTypes.SelectSingleNode(String.Format("//logTypeAlias [. = '{0}']", type.ToString().ToLower())) == null)
                {
                    if (comment.Length > 3999)
                    {
                        comment = comment.Substring(0, 3955) + "...";
                    }

                    if (UmbracoSettings.EnableAsyncLogging)
                    {
                        ThreadPool.QueueUserWorkItem(
                            delegate { AddSynced(type, user == null ? 0 : user.Id, nodeId, comment); });
                        return;
                    }

                    AddSynced(type, user == null ? 0 : user.Id, nodeId, comment);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a log item to the log immidiately instead of Queuing it as a work item.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="comment">The comment.</param>
        public static void AddSynced(LogTypes type, int userId, int nodeId, string comment)
        {
            var logTypeIsAuditType = type.GetType().GetField(type.ToString()).GetCustomAttributes(typeof(AuditTrailLogItem), true).Length != 0;

            if (logTypeIsAuditType)
            {
                try
                {
                    SqlHelper.ExecuteNonQuery(
                        "insert into umbracoLog (userId, nodeId, logHeader, logComment) values (@userId, @nodeId, @logHeader, @comment)",
                        SqlHelper.CreateParameter("@userId", userId),
                        SqlHelper.CreateParameter("@nodeId", nodeId),
                        SqlHelper.CreateParameter("@logHeader", type.ToString()),
                        SqlHelper.CreateParameter("@comment", comment));
                }
                catch (Exception e)
                {
					LogHelper.Error<Log>("An error occurred adding an audit trail log to the umbracoLog table", e);
                }

				//Because 'Custom' log types are also Audit trail (for some wacky reason) but we also want these logged normally so we have to check for this:
				if (type != LogTypes.Custom)
				{
					return;
				}

            }

			//if we've made it this far it means that the log type is not an audit trail log or is a custom log.
			LogHelper.Info<Log>(
				"Redirected log call (please use Umbraco.Core.Logging.LogHelper instead of umbraco.BusinessLogic.Log) | Type: {0} | User: {1} | NodeId: {2} | Comment: {3}",
				() => type.ToString(), () => userId, () => nodeId.ToString(CultureInfo.InvariantCulture), () => comment);            
        }