private static bool IsLogDestination(LogDestination target) { bool result = false; result = (outputTarget & (1 << (int)target)) > 0 ? true : false; return(result); }
public ServiceConfiguration() { #if DEBUG LogDestinations = new LogDestination[] { LogDestination.AppInsights, LogDestination.Console }; #else LogDestinations = new LogDestination[] { LogDestination.AppInsights }; #endif }
/// <summary> /// Create a console or Null log /// </summary> /// <param name="logDestination"></param> public Log(LogDestination logDestination) { if (logDestination == LogDestination.LogFile) { throw new ArgumentException("Log file destination must supply file name"); } _logDestination = logDestination; }
public static void UseOutputMethod(LogDestination target, bool isOpen) { if (isOpen) { outputTarget = outputTarget | (1 << (int)target); } else { outputTarget = outputTarget & (~(1 << (int)target)); } }
public void Log(LogDestination destination, LogType type, string message, params object[] parameters) { switch (destination) { case LogDestination.Console: SetConsoleColors(type); Console.WriteLine(string.Format(message, parameters)); Console.ResetColor(); break; } }
public void LogError(LogDestination destination, Exception ex) { switch (destination) { case LogDestination.Console: SetConsoleColors(LogType.Error); Console.WriteLine(ex); Console.ResetColor(); break; } }
public void Log(LogDestination destination, LogType type, byte[] bytes) { switch (destination) { case LogDestination.Console: SetConsoleColors(type); Console.WriteLine(bytes); Console.ResetColor(); break; } }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("logDestination"); writer.WriteStringValue(LogDestination.ToString()); if (Optional.IsDefined(LogLocationSettings)) { writer.WritePropertyName("logLocationSettings"); writer.WriteObjectValue(LogLocationSettings); } writer.WriteEndObject(); }
/// <summary> /// Creates a Log instance that logs the wanted LogLevel messages immediately to a file. /// </summary> /// <param name="path">Full path to the file to write the log messages to.</param> /// <param name="logMode">The LogMode.</param> public Log(string path, LogMode logMode = LogMode.All) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } CreateLogFile(path); mPath = path; mLogMode = logMode; mLogDestination = LogDestination.File; }
/// <summary> /// Create a log file /// </summary> /// <param name="LogFile">Path to log file</param> public Log(string LogFile) { if (String.IsNullOrEmpty(LogFile)) { throw new ArgumentException("Log file name must be specified"); } _logDestination = LogDestination.LogFile; // Log to a file _logStream = new StreamWriter(LogFile, true, Encoding.Unicode); _logStream.AutoFlush = true; _logFile = LogFile; }
private static IInternalLogger CreateLogger( LogLevel logLevel, LogDestination destination, string filePath) { switch (destination) { case LogDestination.Console: return(new ConsoleLogger(logLevel)); case LogDestination.File: return(new FileLogger(filePath, logLevel)); default: throw new Exception($"Unknown log destination {destination}"); } }
private void ProcessLog(string parameters, LogDestination logDestination) { string value = CollectParts(parameters); if (String.IsNullOrEmpty(value)) { return; } if (logDestination == LogDestination.Log) { Log(value); } else { LogStat(value); } }
public bool LogMessage(string message, LogDestination logDestination, LogType logType) { if (string.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(message), "Message can't be null."); } ILogger logger = logDestination switch { LogDestination.LogToDatabase => _databaseLogger, LogDestination.LogToFile => _fileLogger, LogDestination.LogToConsole => _consoleLogger, _ => throw new ArgumentOutOfRangeException(nameof(logDestination), logDestination, "Invalid configuration"), }; logger.LogMessage(message, logType); return(true); }
public MultiLogger(string cliArgument) { if (cliArgument == null) { return; } string targets = cliArgument.Split('=')[1].ToUpper(); if (targets.Contains('C')) { logDestination |= LogDestination.Console; } if (targets.Contains('F')) { logDestination |= LogDestination.File; } }
/// <summary> /// Initializes a new instance of the <see cref="Log"/> class. /// </summary> /// <param name="logDest">logging destination</param> /// <param name="categoryName">category name for log messages</param> /// <param name="listener">optional trace listener for the TraceSource logging destination</param> public Log(LogDestination logDest, string categoryName, TraceListener listener = null) { var loggerFactory = new LoggerFactory(); this.logger = loggerFactory.CreateLogger(categoryName); if (logDest == LogDestination.Debug) { // the following produces debug output visible in the visual studio output window loggerFactory.AddDebug(); } else if (logDest == LogDestination.Console) { // the following produces output visible in a console window loggerFactory.AddConsole(); } else if (logDest == LogDestination.TraceSource) { if (listener == null) { throw new ArgumentNullException("listener is null"); } var source = new SourceSwitch("sourceSwitch"); source.Level = SourceLevels.All; loggerFactory.AddTraceSource(source, listener); } else if (logDest == LogDestination.EventSource) { // create an event listener var eventListener = new LogEventListener(); // the following produces event source debug output loggerFactory.AddEventSourceLogger(); } }
/// <summary> /// Create an empty log /// </summary> public Log() { // Log to null _logDestination = LogDestination.Null; }
public JobLogger(LogType flagLogType, LogDestination flagLogDestination) { _logType = flagLogType; _logDestination = flagLogDestination; }
} = LogDestination.None; //read-only property, also initialized to a value. Thank you C#.. public bool CanLogToOutput(LogDestination logDestination) => ((LogDestination & logDestination) == logDestination);
/// <summary> /// Creates a Log instance that logs the wanted LogLevel messages to the memory. /// </summary> public Log(LogMode logMode) { mLogMode = logMode; mLogDestination = LogDestination.Memory; }
/// <summary> /// Creates a Log instance that logs All LogLevel messages to the memory. /// </summary> public Log() { mLogMode = Utils.LogMode.All; mLogDestination = LogDestination.Memory; }
public void LogMessage_UsingInlineData_Successfully(LogDestination logDestination, LogType logType, LoggerConsoleApplication.JobLogger.JobLogger jobLogger, string message) { var result = jobLogger.LogMessage(message, logDestination, logType); Assert.True(result); }
public void Initialise(LogLevel logLevel, LogDestination destination, string filePath) { _inner = CreateLogger(logLevel, destination, filePath); }
/// <summary> /// Creates a Log instance that logs the wanted LogLevel messages immediately to a file. /// </summary> /// <param name="path">Full path to the file to write the log messages to.</param> /// <param name="logMode">The LogMode.</param> public Log(string path, LogMode logMode = LogMode.All) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); CreateLogFile(path); mPath = path; mLogMode = logMode; mLogDestination = LogDestination.File; }
public void LogUserStatsBody(int maxNumber, LogDestination destination) { List<RaceStatsUsers> stats = race.GetUserStats(); int possition = 1; for (int i = 0; i < stats.Count; i++) { if (i >= maxNumber) { break; } RaceStatsUsers item = stats [i]; switch (destination) { case LogDestination.IoFtpdLog: Log.IoFtpd(FormatUserStats(possition, item, Config.LogLineIoFtpdUserStatsBody)); break; default: Log.Internal(FormatUserStats(possition, item, Config.LogLineInternalUserStatsBody)); break; } possition++; } }