示例#1
0
        /// <summary>
        /// Records a message to the System Log.
        /// </summary>
        /// <param name="message">The Log Message.</param>
        /// <param name="entryType">The Type of the Entry.</param>
        /// <param name="user">The User.</param>
        /// <param name="wiki">The wiki, <c>null</c> if is an application level log.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="message"/> or <paramref name="user"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="message"/> or <paramref name="user"/> are empty.</exception>
        public void LogEntry(string message, EntryType entryType, string user, string wiki)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message.Length == 0)
            {
                throw new ArgumentException("Message cannot be empty", "message");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (user.Length == 0)
            {
                throw new ArgumentException("User cannot be empty", "user");
            }

            DateTime dateTime = DateTime.UtcNow;

            LogEntity logEntity = new LogEntity()
            {
                PartitionKey = "0",
                RowKey       = dateTime.Ticks + "-" + Guid.NewGuid().ToString("N"),
                Type         = EntryTypeToString(entryType),
                DateTime     = dateTime,
                User         = user,
                Message      = message,
                Wiki         = wiki
            };
            CloudTable     table           = _cloudTableClient.GetTableReference(LogsTable);
            TableOperation insertOperation = TableOperation.Insert(logEntity);

            table.Execute(insertOperation);

            int logSize = LogSize;

            if (logSize > int.Parse(_host.GetGlobalSettingValue(GlobalSettingName.MaxLogSize)))
            {
                CutLog((int)(logSize * 0.75));
            }
        }
        /// <summary>
        /// Records a message to the System Log.
        /// </summary>
        /// <param name="message">The Log Message.</param>
        /// <param name="entryType">The Type of the Entry.</param>
        /// <param name="user">The User.</param>
        /// <param name="wiki">The wiki, <c>null</c> if is an application level log.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="message"/> or <paramref name="user"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="message"/> or <paramref name="user"/> are empty.</exception>
        public void LogEntry(string message, EntryType entryType, string user, string wiki)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message.Length == 0)
            {
                throw new ArgumentException("Message cannot be empty", "message");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (user.Length == 0)
            {
                throw new ArgumentException("User cannot be empty", "user");
            }

            DateTime dateTime = DateTime.UtcNow;

            LogEntity logEntity = new LogEntity()
            {
                PartitionKey = "0",
                RowKey       = dateTime.Ticks + "-" + Guid.NewGuid().ToString("N"),
                Type         = EntryTypeToString(entryType),
                DateTime     = dateTime,
                User         = user,
                Message      = message,
                Wiki         = wiki
            };

            _context.AddObject(LogsTable, logEntity);
            _context.SaveChangesStandard();

            int logSize = LogSize;

            if (logSize > int.Parse(_host.GetGlobalSettingValue(GlobalSettingName.MaxLogSize)))
            {
                CutLog((int)(logSize * 0.75));
            }
        }