Beispiel #1
0
 public void ErrorWithMsgShouldNotCallUnderlyingErrorWhenErrorIsDisabled()
 {
     underlyingLoggerMock.Setup(l => l.IsErrorEnabled).Returns(false);
     isErrorEnabledResolverMock.Setup(r => r.Value).Returns(underlyingLoggerMock.Object.IsErrorEnabled);
     logger.Error("msg");
     underlyingLoggerMock.Verify(l => l.Error(It.IsAny <string>()), Times.Never());
 }
Beispiel #2
0
        public ToolBarItem()
        {
            ToolbarClick = new DelegateCommand <ToolBarCommandParam>(new Action <ToolBarCommandParam>((o) =>
            {
                try
                {
                    if (toolBarItemEvent != null)
                    {
                        toolBarItemEvent(this, new ToolBarItemArg()
                        {
                            Index = this.index, OpenStyle = this.openStyle, OpenUri = this.openUri, IconUri = this.iconUri, Title = this.title
                        });
                    }

                    if (string.Equals(o.OpenStyle, "_blank"))
                    {
                        if (o.OpenUri != "")
                        {
                            MainPortal.PortalRegionManager.RequestNavigate("PopupWindow", new Uri(o.OpenUri, UriKind.Relative));
                        }
                    }
                    else
                    {
                        if (o.OpenUri != "")
                        {
                            MainPortal.PortalRegionManager.RequestNavigate("WindowAreaRoot", new Uri(o.OpenUri, UriKind.Relative));
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerFacade.Error("Navigation exception!May be due to the configuration of the interface type not in the container.");
                }
            }), (o) => { return(true); });
        }
Beispiel #3
0
        //get a value from WMI
        public static string GetWmiString(string NameSpace, string WmiQuery)
        {
            string s = null;

            try
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(NameSpace, WmiQuery))
                {
                    foreach (ManagementObject m in searcher.Get())
                    {
                        foreach (PropertyData propdata in m.Properties)
                        {
                            s = s + propdata.Value;
                        }
                    }
                }

                if (String.IsNullOrEmpty(s))
                {
                    return(null);
                }
                else
                {
                    return(s);
                }
            }
            catch
            {
                LoggerFacade.Error("Error running query against namespace " + NameSpace + ": " + WmiQuery);
                return(null);
            }
        }
Beispiel #4
0
        void ShouldNotLogEverything()
        {
            // Arrange
            var logStrategy = new Mock <ILogStrategy>();

            logStrategy.Setup(x => x.WriteMessage(It.IsAny <string>())).Verifiable();
            var shouldLog = LogLevel.Fatal | LogLevel.Info | LogLevel.Warn;
            var logger    = new LoggerFacade <RawLogger>(new LoggerSettings
            {
                LogLevel           = shouldLog,
                DefaultLogStrategy = logStrategy.Object
            });

            // Act
            logger.Debug("debug");
            logger.Error("error");
            logger.Fatal("fatal");
            logger.Info("info;");
            logger.Warn("warm;");

            // Assert
            logStrategy.Verify(x => x.WriteMessage(It.IsAny <string>()), Times.Exactly(3));


            foreach (var logLevel in Enum.GetValues(typeof(LogLevel)))
            {
                var logLevelEnum = (LogLevel)logLevel;
                if ((logLevelEnum & shouldLog) != LogLevel.None)
                {
                    logStrategy.Verify(x => x.WriteMessage(It.Is <string>(s => s.Contains($"{logLevelEnum}"))), Times.Once);
                }
            }
        }
Beispiel #5
0
        public override bool HandleException(System.Exception exception)
        {
            ILoggerFacade logger = new LoggerFacade();

            logger.Error("Data access exception", exception);
            throw exception;
            return(true);
        }
Beispiel #6
0
 public static ManagementObjectCollection GetWmiManagementObjectCollection(string NameSpace, string WmiQuery)
 {
     try
     {
         using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(NameSpace, WmiQuery))
         { return(searcher.Get()); }
     }
     catch
     {
         LoggerFacade.Error("Error running query against namespace " + NameSpace + ": " + WmiQuery);
         return(null);
     }
 }
Beispiel #7
0
 //Exception handler methods
 #region
 public void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args)
 {
     args.Handled = true;
     if (args.Exception is System.IO.FileNotFoundException)
     {
         LoggerFacade.Error("System.IO.FileNotFoundException logged. This is a known issue with DragDrop");
     }
     else
     {
         LoggerFacade.Fatal("OnDispatcherUnhandledException:" + args.Exception.ToString());
         LoggerFacade.Fatal("OnDispatcherUnhandledException:" + args.Exception.Message);
         this.HandleException(sender, args.Exception, args.Exception.StackTrace);
     }
 }