Пример #1
0
        /// <summary>
        /// Method that filters the messages to be logged
        /// </summary>
        /// <param name="message"></param>
        /// <param name="category">Debug/Info/Warn/Exception</param>
        /// <param name="priority">Low/Medium/High</param>
        public void Log(string message, Category category, Priority priority)
        {
            LoggingDefinitions.LoggingOperationsClient client = new LoggingDefinitions.LoggingOperationsClient();
            client.Endpoint.Behaviors.Add(new CookieBehavior());

            #region Async Call
            //Async Call based on Category Type, LogLevel and Priority
            if (LogLevel == DEFAULT_LEVEL)
            {
                client.LogToFileAsync(message, Category.Info.ToString(), Priority.Low.ToString());
            }

            else if (category == Category.Debug && LogLevel >= DEBUG_LEVEL)
            {
                client.LogToFileAsync(message, category.ToString(), priority.ToString());
            }

            else if (category == Category.Info && LogLevel >= INFO_LEVEL)
            {
                client.LogToFileAsync(message, category.ToString(), priority.ToString());
            }

            else if (category == Category.Exception && LogLevel >= WARN_LEVEL && priority == Priority.Low)
            {
                client.LogToFileAsync(message, category.ToString(), priority.ToString());
            }

            else if (category == Category.Exception && LogLevel >= ERROR_LEVEL && priority == Priority.Medium)
            {
                client.LogToFileAsync(message, category.ToString(), priority.ToString());
            }

            else if (category == Category.Exception && LogLevel >= FATAL_LEVEL && priority == Priority.High)
            {
                client.LogToFileAsync(message, category.ToString(), priority.ToString());
            }
            #endregion

            #region Completion Event
            client.LogToFileCompleted += (se, e) =>
            {
                if (e.Error != null)
                {
                    Prompt.ShowDialog(e.Error.InnerException.Message);
                }
            };
            #endregion
        }
Пример #2
0
 /// <summary>
 /// Constructor - Initialize LogLevel from Web Config
 /// </summary>
 public Logger()
 {
     if (LogLevel == DEFAULT_LEVEL)
     {
         LoggingDefinitions.LoggingOperationsClient client = new LoggingDefinitions.LoggingOperationsClient();
         client.Endpoint.Behaviors.Add(new CookieBehavior());
         client.GetLoggingLevelAsync();
         client.GetLoggingLevelCompleted += (s, ea) =>
         {
             try
             {
                 LogLevel = ea.Result;
             }
             catch (TargetInvocationException ex)
             {
                 Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + ex.StackTrace, "Exception", MessageBoxButton.OK);
             }
         };
     }
 }