private IXapLoggingContext GetLoggingContext(string configurationKey) { IXapLoggingContext loggingContext = LoggingContext.Create(); if (XapConfig.Instance.ContainsKey($"{configurationKey}", "debugOn")) { loggingContext.DebugOn = XapConfig.Instance.GetValue <bool>($"{configurationKey}", "debugOn"); } if (XapConfig.Instance.ContainsKey($"{configurationKey}", "verboseOn")) { loggingContext.VerboseOn = XapConfig.Instance.GetValue <bool>($"{configurationKey}", "verboseOn"); } if (XapConfig.Instance.ContainsKey($"{configurationKey}", "logFile")) { loggingContext.LogFileLocation = XapConfig.Instance.GetValue <string>($"{configurationKey}", "logFile"); } if (XapConfig.Instance.ContainsKey($"{configurationKey}", "providerType")) { loggingContext.ProviderType = XapConfig.Instance.GetValue <string>($"{configurationKey}", "providerType"); } if (XapConfig.Instance.ContainsKey($"{configurationKey}", "loggingLevel")) { string level = XapConfig.Instance.GetValue <string>($"{configurationKey}", "loggingLevel"); switch (level) { case "debug": loggingContext.LoggingLevel = (uint)LoggerLevel.Debug; break; case "info": loggingContext.LoggingLevel = (uint)LoggerLevel.Info; break; case "success": loggingContext.LoggingLevel = (uint)LoggerLevel.Success; break; case "warning": loggingContext.LoggingLevel = (uint)LoggerLevel.Warning; break; case "error": loggingContext.LoggingLevel = (uint)LoggerLevel.Error; break; case "fatal": loggingContext.LoggingLevel = (uint)LoggerLevel.Fatal; break; default: loggingContext.LoggingLevel = (uint)LoggerLevel.All; break; } } return(loggingContext); }
public IXapLoggingProvider LoadLoggingProvider(IXapLoggingContext loggingContext) { try { return(AssemblyManager.Instance.CreateInstance <IXapLoggingProvider>(loggingContext.ProviderType)); } catch (Exception ex) { throw new XapException($"Error loading logging provider {loggingContext.ProviderType}", ex); } }
protected virtual bool StartLog(IXapLoggingContext loggingContext) { if (string.IsNullOrWhiteSpace(loggingContext.LogFileLocation)) { _logFilename = XapEnvironment.Instance.MapFolderPath(XapConfig.Instance.GetValue <string>($"{XapEnvironment.Instance.EnvironmentName}.logging", "logFile")); } else { _logFilename = loggingContext.LogFileLocation; } _bAppend = loggingContext.AppendToLog; _levels = loggingContext.LoggingLevel; lock (this) { // Fail if logging has already been started if (_loggerState != LoggerState.Stopped) { return(false); } // Fail if the log file isn't specified if (String.IsNullOrEmpty(_logFilename)) { return(false); } // Delete log file if it exists if (!_bAppend) { try { File.Delete(_logFilename); } catch (Exception) { return(false); } } // Open file for writing - return on error if (!File.Exists(_logFilename)) { try { _logFile = File.CreateText(_logFilename); } catch (Exception) { _logFile = null; return(false); } } else { try { _logFile = File.AppendText(_logFilename); } catch { _logFile = null; return(false); } } _logFile.AutoFlush = true; // Return successfully _loggerState = LoggerState.Running; return(true); } }
bool IXapLoggingProvider.Start(IXapLoggingContext loggingContext) { return(StartLog(loggingContext)); }