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); }
static Program() { var config = new LoggingConfiguration(); config.AddTarget(LogLevel.Trace, LogLevel.Fatal, new MyTarget(THRESHOLD)); Logger = LogManagerFactory.CreateLogManager(config).GetLogger("MyTestLog"); }
public static ContainerBuilder RegisterLogManager(this ContainerBuilder builder) { var logManager = new LogManagerFactory().Create(); builder.RegisterInstance <ILogManager>(logManager).SingleInstance(); return(builder); }
static LoggingModule() { var loggingConfiguration = new LoggingConfiguration(); loggingConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new DebugTarget()); LogManager = LogManagerFactory.CreateLogManager(loggingConfiguration); }
public void Constructor_CreateInstanceWhenNoFacotryIsRegistered_LogManagerFactoryReturnsInstance() { LogManagerFactory.RegisterFactory(null); var manager = A.Fake <AutoRegistratingLogManager>(); Assert.AreSame(manager, LogManagerFactory.GetLogManager()); }
public void Constructor_CreateInstance_LogManagerIsSameAsFromFactory() { var ldapConfig = A.Fake <ILdapConfig>(); var container = new Container(ldapConfig); Assert.AreSame(LogManagerFactory.GetLogManager(), container.LogManager); }
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; }
public void GetLogManager_RegisterFactoryMethod_ReturnsInstanceFromFactory() { var manager = A.Fake <ILogManager>(); LogManagerFactory.RegisterFactory(() => manager); var result = LogManagerFactory.GetLogManager(); Assert.AreSame(manager, result); }
void HandleRegisterJsonPostTarget(object sender, RoutedEventArgs e) { this.DoJsonPost = true; var settings = CreateNewSettings(); this.Log = LogManagerFactory.CreateLogManager(settings).GetLogger <LogSamplePage>(); // set... this.buttonJsonPost.IsEnabled = false; }
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; }
/// <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(); }
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); }
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); }
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); } }
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>())); }
public void TearDown() { // Reset manager after every test LogManagerFactory.RegisterFactory(null); }
public void RegisterFactory_RegisterNullFactoryMethod_ReturnsFalse() { LogManagerFactory.RegisterFactory(null); Assert.IsFalse(LogManagerFactory.FactoryRegistered); }
public void RegisterFactory_RegisterFactoryMethod_ReturnsTrue() { LogManagerFactory.RegisterFactory(A.Fake <ILogManager>); Assert.IsTrue(LogManagerFactory.FactoryRegistered); }
public void GetLogManager_GetDefaultInstance_ReturnsNullLogManager() { var instance = LogManagerFactory.GetLogManager(); Assert.IsInstanceOf <NullLogManager>(instance); }
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))); }