예제 #1
0
        public async Task TestGetZipFile()
        {
            var manager = LogManagerFactory.CreateLogManager() as IWinRTLogManager;

            var logger = (ILoggerAsync)manager.GetLogger("test");

            // send through a log entry...
            var op = await logger.FatalAsync("Testing file write...", new InvalidOperationException("An exception message..."));

            var file = await manager.GetCompressedLogFile();

            Assert.True(file.Name.EndsWith(".zip"));

            var target = manager.DefaultConfiguration.GetTargets().OfType <FileTargetBase>().First();

            await target.ForceCleanupAsync();

            var exceptionThrow = false;

            try
            {
                var str = await file.OpenReadAsync();
            }
            catch (FileNotFoundException)
            {
                exceptionThrow = true;
            }

            Assert.True(exceptionThrow);
        }
예제 #2
0
        static Program()
        {
            var config = new LoggingConfiguration();

            config.AddTarget(LogLevel.Trace, LogLevel.Fatal, new MyTarget(THRESHOLD));
            Logger = LogManagerFactory.CreateLogManager(config).GetLogger("MyTestLog");
        }
예제 #3
0
        public static ContainerBuilder RegisterLogManager(this ContainerBuilder builder)
        {
            var logManager = new LogManagerFactory().Create();

            builder.RegisterInstance <ILogManager>(logManager).SingleInstance();
            return(builder);
        }
예제 #4
0
        static LoggingModule()
        {
            var loggingConfiguration = new LoggingConfiguration();

            loggingConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new DebugTarget());
            LogManager = LogManagerFactory.CreateLogManager(loggingConfiguration);
        }
예제 #5
0
        public void Constructor_CreateInstanceWhenNoFacotryIsRegistered_LogManagerFactoryReturnsInstance()
        {
            LogManagerFactory.RegisterFactory(null);
            var manager = A.Fake <AutoRegistratingLogManager>();

            Assert.AreSame(manager, LogManagerFactory.GetLogManager());
        }
예제 #6
0
        public void Constructor_CreateInstance_LogManagerIsSameAsFromFactory()
        {
            var ldapConfig = A.Fake <ILdapConfig>();

            var container = new Container(ldapConfig);

            Assert.AreSame(LogManagerFactory.GetLogManager(), container.LogManager);
        }
예제 #7
0
        private void HandleRegisterStreamingTarget(object sender, RoutedEventArgs e)
        {
            this.DoFileStreaming = true;
            var settings = CreateNewSettings();

            this.Log = LogManagerFactory.CreateLogManager(settings).GetLogger <LogSamplePage>();

            // set...
            this.buttonFileStreaming.IsEnabled = false;
        }
예제 #8
0
        public void GetLogManager_RegisterFactoryMethod_ReturnsInstanceFromFactory()
        {
            var manager = A.Fake <ILogManager>();

            LogManagerFactory.RegisterFactory(() => manager);

            var result = LogManagerFactory.GetLogManager();

            Assert.AreSame(manager, result);
        }
예제 #9
0
        void HandleRegisterJsonPostTarget(object sender, RoutedEventArgs e)
        {
            this.DoJsonPost = true;
            var settings = CreateNewSettings();


            this.Log = LogManagerFactory.CreateLogManager(settings).GetLogger <LogSamplePage>();

            // set...
            this.buttonJsonPost.IsEnabled = false;
        }
예제 #10
0
        private void HandleRegisterSQLiteTarget(object sender, RoutedEventArgs e)
        {
            this.DoSqlite = true;
            var settings = CreateNewSettings();

            // reset...
            this.Log = LogManagerFactory.CreateLogManager(settings).GetLogger <LogSamplePage>();

            // set...
            this.buttonSQLite.IsEnabled     = false;
            this.buttonReadSQLite.IsEnabled = true;
        }
예제 #11
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            var settings = LogManagerFactory.CreateLibraryDefaultSettings();

            settings.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget());
            Log = LogManagerFactory.CreateLogManager(settings).GetLogger <App>();

            this.InitializeComponent();
            this.Suspending += OnSuspending;

            UnhandledException += App_UnhandledException;
            GlobalCrashHandler.Configure();
        }
예제 #12
0
        private LoggingConfiguration CreateNewSettings()
        {
            var settings = LogManagerFactory.CreateLibraryDefaultSettings();

            if (this.DoFileStreaming)
            {
                settings.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget());
            }
            if (this.DoJsonPost)
            {
                settings.AddTarget(LogLevel.Trace, LogLevel.Fatal, new JsonPostTarget(5, new Uri("http://localhost/metrologweb/ReceiveLogEntries.ashx")));
            }
            if (this.DoSqlite)
            {
                this.SQLiteTarget = new SQLiteTarget();
                settings.AddTarget(LogLevel.Trace, LogLevel.Fatal, this.SQLiteTarget);
            }

            // return...
            return(settings);
        }
예제 #13
0
        public static void Log(string systemName, string moduleName, string fileName, string messageInfo)
        {
            ConnectionStringSettings connstr = ConfigurationManager.ConnectionStrings["SparkServiceDesk_LogManagerConnectionString"];
            DBOperator  db         = DBOperatorFactory.GetDBOperator(connstr);
            ILogManager logManager = LogManagerFactory.CreateLogManager("DEFAULT");

            logManager.DB = db;
            BusinessLog bizLog = new BusinessLog();

            bizLog.SystemName   = systemName;
            bizLog.ModuleName   = moduleName;
            bizLog.CategoryName = "上传文件";
            bizLog.KeyString    = fileName;
            bizLog.Operation    = "上传文件";
            bizLog.PriorStatus  = "操作前";
            bizLog.PostStatus   = "操作后";
            bizLog.MessageInfo  = messageInfo;
            bizLog.OperatorID   = "-1";
            bizLog.OperatorName = "无名氏";
            logManager.AppendLog(bizLog);
        }
예제 #14
0
        public async Task TestGetZipNetFile()
        {
            var manager = new LogManager(LogManagerFactory.CreateLibraryDefaultSettings());

            manager.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new StreamingFileTarget());

            var logger = (ILoggerAsync)manager.GetLogger("test");
            // send through a log entry...
            await logger.DebugAsync("Test Message");

            var str = await manager.GetCompressedLogs();

            var file =
                new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory, Environment.SpecialFolderOption.None), "logs.zip"));



            using (var stream = file.Create())
            {
                await str.CopyToAsync(stream);
            }
        }
예제 #15
0
 public static void Initialize(LoggingConfiguration configuration)
 {
     _logManager = LogManagerFactory.CreateLogManager(configuration);
 }
 static LoggerFactory()
 {
     LogManagerFactory.DefaultConfiguration =
         LogManagerFactory.CreateLibraryDefaultSettings();
 }
 public IPortableLogger CreateLogger <T>()
 {
     return(new MetroLogLogger(typeof(T).Name, LogManagerFactory.CreateLogManager().GetLogger <T>()));
 }
예제 #18
0
 public void TearDown()
 {
     // Reset manager after every test
     LogManagerFactory.RegisterFactory(null);
 }
예제 #19
0
 public void RegisterFactory_RegisterNullFactoryMethod_ReturnsFalse()
 {
     LogManagerFactory.RegisterFactory(null);
     Assert.IsFalse(LogManagerFactory.FactoryRegistered);
 }
예제 #20
0
 public void RegisterFactory_RegisterFactoryMethod_ReturnsTrue()
 {
     LogManagerFactory.RegisterFactory(A.Fake <ILogManager>);
     Assert.IsTrue(LogManagerFactory.FactoryRegistered);
 }
예제 #21
0
        public void GetLogManager_GetDefaultInstance_ReturnsNullLogManager()
        {
            var instance = LogManagerFactory.GetLogManager();

            Assert.IsInstanceOf <NullLogManager>(instance);
        }
예제 #22
0
 public void SetUp()
 {
     // Reset manager before every test
     LogManagerFactory.RegisterFactory(null);
 }
 /// <summary>
 /// The create logger.
 /// </summary>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <returns>
 /// The <see cref="IPortableLogger"/>.
 /// </returns>
 public IPortableLogger CreateLogger(string name)
 {
     return(new MetroLogLogger(name, LogManagerFactory.CreateLogManager().GetLogger(name)));
 }