示例#1
0
    private static bool IsLogDestination(LogDestination target)
    {
        bool result = false;

        result = (outputTarget & (1 << (int)target)) > 0 ? true : false;
        return(result);
    }
示例#2
0
    public ServiceConfiguration()
    {
#if DEBUG
        LogDestinations = new LogDestination[] { LogDestination.AppInsights, LogDestination.Console };
#else
        LogDestinations = new LogDestination[] { LogDestination.AppInsights };
#endif
    }
示例#3
0
        /// <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;
        }
示例#4
0
文件: Log.cs 项目: hoeness2/mcebuddy2
        /// <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;
        }
示例#5
0
 public static void UseOutputMethod(LogDestination target, bool isOpen)
 {
     if (isOpen)
     {
         outputTarget = outputTarget | (1 << (int)target);
     }
     else
     {
         outputTarget = outputTarget & (~(1 << (int)target));
     }
 }
示例#6
0
 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;
     }
 }
示例#7
0
 public void LogError(LogDestination destination, Exception ex)
 {
     switch (destination)
     {
     case LogDestination.Console:
         SetConsoleColors(LogType.Error);
         Console.WriteLine(ex);
         Console.ResetColor();
         break;
     }
 }
示例#8
0
 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();
 }
示例#10
0
        /// <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;
        }
示例#11
0
文件: Log.cs 项目: hoeness2/mcebuddy2
        /// <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;
        }
示例#12
0
        /// <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;
        }
示例#13
0
        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}");
            }
        }
示例#14
0
        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;
            }
        }
示例#17
0
        /// <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();
            }
        }
示例#18
0
文件: Log.cs 项目: hoeness2/mcebuddy2
 /// <summary>
 /// Create an empty log
 /// </summary>
 public Log()
 {
     // Log to null
     _logDestination = LogDestination.Null;
 }
示例#19
0
 public JobLogger(LogType flagLogType,
                  LogDestination flagLogDestination)
 {
     _logType = flagLogType;
     _logDestination = flagLogDestination;
 }
示例#20
0
 /// <summary>
 /// Create an empty log
 /// </summary>
 public Log()
 {
     // Log to null
     _logDestination = LogDestination.Null;
 }
示例#21
0
 } = LogDestination.None;                                             //read-only property, also initialized to a value. Thank you C#..
 public bool CanLogToOutput(LogDestination logDestination) => ((LogDestination & logDestination) == logDestination);
示例#22
0
 /// <summary>
 /// Creates a Log instance that logs the wanted LogLevel messages to the memory.
 /// </summary>
 public Log(LogMode logMode)
 {
     mLogMode = logMode;
     mLogDestination = LogDestination.Memory;
 }
示例#23
0
 /// <summary>
 /// Creates a Log instance that logs the wanted LogLevel messages to the memory.
 /// </summary>
 public Log(LogMode logMode)
 {
     mLogMode        = logMode;
     mLogDestination = LogDestination.Memory;
 }
示例#24
0
 /// <summary>
 /// Creates a Log instance that logs All LogLevel messages to the memory.
 /// </summary>
 public Log()
 {
     mLogMode        = Utils.LogMode.All;
     mLogDestination = LogDestination.Memory;
 }
示例#25
0
        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);
        }
示例#26
0
 /// <summary>
 /// Creates a Log instance that logs All LogLevel messages to the memory.
 /// </summary>
 public Log()
 {
     mLogMode = Utils.LogMode.All;
     mLogDestination = LogDestination.Memory;
 }
示例#27
0
 public void Initialise(LogLevel logLevel, LogDestination destination, string filePath)
 {
     _inner = CreateLogger(logLevel, destination, filePath);
 }
示例#28
0
        /// <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;
        }
示例#29
0
 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++;
     }
 }