private DLoggerManager(String appName, Boolean forceDummy) { if (ForceAllToDummy || forceDummy) { _defaultLogger = new DummyDLogger(); } else { if (DLoggerConfig.LoadDefault(appName, out _config)) { InitialiseDefaultLogger(); if (_config.DefaultEnabled) { _defaultLogger = new DLogger(_config); } else { _defaultLogger = new DummyDLogger(); } } else { _defaultLogger = new DummyDLogger(); } } }
public DLogger(DLoggerConfig config) { _lock = new Object(); _config = config; _isDefault = true; _name = config.DefaultLoggerName; _allowedMessgeTypes = config.DefaultMessageTypes; String outputPath = DLoggerConfig.ParsePath(config.PathOutput); if (!outputPath.EndsWith("/")) { outputPath += "/"; } _fullPath = String.Format(@"{0}{1}.log", outputPath, _name); LogStartupMessages(); //Log(LoggerMessageType.Naked, // new String('-', 50) + Environment.NewLine); //Log(LoggerMessageType.Information | LoggerMessageType.Success, // "Logger initialised for '{0}', with allowed message types of '{1}'. Output file is located at '{2}'.", // _name, // _allowedMessgeTypes, // _fullPath); }
public static Boolean LoadDefault(String appName, out DLoggerConfig loadedConfig) { loadedConfig = null; String appDataPath = String.Empty; if (!Core.IO.Directory.ResolvePath("{AppData}", out appDataPath)) { return(false); } if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter)) { appDataPath += DLoggerManager.PathDelimiter; } String configPath = String.Format("{0}{1}", appDataPath, String.Format(@"Config{0}logger.config.json", DLoggerManager.PathDelimiter)); new FileInfo(configPath).Directory.Create(); if (!File.Exists(configPath)) { Assembly thisAssembly = typeof(DLoggerConfig).Assembly; string embeddedConfigPath = string.Empty; #if DEBUG embeddedConfigPath = "devoctomy.DFramework.Logging.Assets.debug.logger.config.json"; #else embeddedConfigPath = "devoctomy.DFramework.Logging.Assets.release.logger.config.json"; #endif using (Stream stream = thisAssembly.GetManifestResourceStream(embeddedConfigPath)) { using (StreamReader reader = new StreamReader(stream)) { String template = reader.ReadToEnd(); template = template.Replace("{AppName}", appName); File.WriteAllText(configPath, template); } } } if (File.Exists(configPath)) { String loggerConfigJSON = File.ReadAllText(configPath); loadedConfig = new DLoggerConfig(configPath, loggerConfigJSON); return(true); } else { throw new FileNotFoundException(String.Format("The logger config '{0}' was not found.", configPath)); //return (false); } }