Exemple #1
0
        private void InitialiseLogger()
        {
            BlackBox.LogConfiguration loggerConfig = new BlackBox.LogConfiguration();

            string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string logPath = Path.Combine(applicationData, "TestIt");
            try
            {                
                if (!Directory.Exists(logPath))
                {
                    Directory.CreateDirectory(logPath);
                }

                loggerConfig.Sinks.Add(new BlackBox.FileSink() { FileName = Path.Combine(logPath, "log.txt"), Name = "File", Format = "$(time(format='HH:mm:ss')): $(message())" });

            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("There was an error initializing the logging component.\nThe application will now run without logging");

                loggerConfig.Sinks.Add(new NullSink());
            }

            
            BlackBox.LogKernel kernel = new BlackBox.LogKernel(loggerConfig);

            _container.RegisterInstance<BlackBox.ILogKernel>(kernel);
            _container.Register<BlackBox.ILogger>(x => x.Resolve<BlackBox.ILogKernel>().GetLogger());
            _container.Register<ILogger, BlkBxLogger>();
        }
Exemple #2
0
        protected virtual void InitializeLogger()
        {
            BlackBox.FileSink fileTarget = new BlackBox.FileSink(){
                FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TestIt", "test.client.log"),
                Name = "FileLogger"
            };

            BlackBox.LogConfiguration configuration = new BlackBox.LogConfiguration();
            configuration.Sinks.Add(fileTarget);

            BlackBox.ILogKernel kernel = new BlackBox.LogKernel(configuration);

            _container.RegisterInstance<BlackBox.ILogKernel>(kernel);
            _container.Register<BlackBox.ILogger>(x => x.Resolve<BlackBox.ILogKernel>().GetLogger());
            _container.Register<ILogger, BlkBxLogger>();
        }