Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileTarget"/> class.
        /// </summary>
        /// <param name="name">Unique name for this target. Could be the file name</param>
        /// <param name="configuration">The configuration.</param>
        public FileTarget(string name, FileConfiguration configuration)
        {
            Contract.Requires(!String.IsNullOrEmpty(name));
            Contract.Requires<ArgumentNullException>(configuration != null);

            _fileWriter = new FileWriter(name, configuration);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileTarget"/> class.
        /// </summary>
        /// <param name="name">File name without extension.</param>
        /// <param name="configuration">The configuration.</param>
        public FileTarget(string name, FileConfiguration configuration)
        {
            if (name == null) throw new ArgumentNullException("name");
            if (configuration == null) throw new ArgumentNullException("configuration");

            _fileWriter = new FileWriter(name, configuration);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a new log file
        /// </summary>
        /// <param name="fileName">Target file without path (Path is configured in <paramref name="configuration"/>).</param>
        /// <param name="configuration">Configuration used to control how entries should be written to the file</param>
        public static void AddFile(string fileName, FileConfiguration configuration)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(fileName));
            Contract.Requires<ArgumentNullException>(configuration != null);

            CreateIfNeeded();
            Targets.Add(new PaddedFileTarget(fileName, configuration));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileWriter"/> class.
        /// </summary>
        /// <param name="name">Fle name.</param>
        /// <param name="configuration">The configuration.</param>
        public FileWriter(string name, FileConfiguration configuration)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(name));
            Contract.Requires<ArgumentNullException>(configuration != null);

            _name = name;
            _configuration = configuration;
            _logDate = DateTime.Today;
        }
Ejemplo n.º 5
0
        public void TestLogging()
        {
            var config = new FileConfiguration
                {
                    CreateDateFolder = true,
                    DaysToKeep = 3,
                    Path = AppDomain.CurrentDomain.BaseDirectory
                };

            var target = new FileTarget("Everything", config);

            target.Enqueue(new LogEntry
                {
                    CreatedAt = DateTime.Now,
                    LogLevel = LogLevel.Debug,
                    Message = "Hello world",
                    LoggedType = GetType(),
                    MethodName = MethodBase.GetCurrentMethod().Name,
                    ThreadId = Thread.CurrentThread.ManagedThreadId,
                    UserName = Thread.CurrentPrincipal.Identity.Name
                               ?? Environment.UserName
                });

            var target2 = new PaddedFileTarget("EVeryone", config);
            target2.Enqueue(new LogEntry
                {
                    CreatedAt = DateTime.Now,
                    LogLevel = LogLevel.Debug,
                    Message = "Hello world",
                    LoggedType = GetType(),
                    MethodName = MethodBase.GetCurrentMethod().Name,
                    ThreadId = Thread.CurrentThread.ManagedThreadId,
                    UserName = Thread.CurrentPrincipal.Identity.Name
                               ?? Environment.UserName
                });

            var logger = new Logger(GetType(), new[] {target2, target});
            logger.Info("Hello");
            logger.Debug("Hello");
            logger.Warning("Hello");
            logger.Error("Hello");
        }
Ejemplo n.º 6
0
        public void TestLogging()
        {
            var config = new FileConfiguration
                             {
                                 CreateDateFolder = true,
                                 DaysToKeep = 3,
                                 Path = @"d:\logfiles"
                             };

            var target = new FileTarget("Everything", config);

            target.Enqueue(new LogEntry
                               {
                                   CreatedAt = DateTime.Now,
                                   LogLevel = LogLevel.Debug,
                                   Message = "Hello world",
                                   StackFrames = new StackTrace().GetFrames(),
                                   ThreadId = Thread.CurrentThread.ManagedThreadId,
                                   UserName = Thread.CurrentPrincipal.Identity.Name
                                              ?? Environment.UserName
                               });

            var target2 = new PaddedFileTarget("EVeryone", config);
            target2.Enqueue(new LogEntry
                                {
                                    CreatedAt = DateTime.Now,
                                    LogLevel = LogLevel.Debug,
                                    Message = "Hello world",
                                    StackFrames = new StackTrace().GetFrames(),
                                    ThreadId = Thread.CurrentThread.ManagedThreadId,
                                    UserName = Thread.CurrentPrincipal.Identity.Name
                                               ?? Environment.UserName
                                });

            var logger = new Logger(GetType(), new[] {target2, target});
            logger.Info("Hello");
            logger.Debug("Hello");
            logger.Warning("Hello");
            logger.Error("Hello");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds the file.
 /// </summary>
 /// <param name="fileName">Absolute or application relative path to the log file</param>
 /// <remarks>
 /// Will used the default settings for <see cref="FileConfiguration"/>.
 /// </remarks>
 public void AddFile(string fileName)
 {
     var configuration = new FileConfiguration
         {
             Path = Path.IsPathRooted(fileName)
                        ? Path.GetDirectoryName(fileName)
                        : AppDomain.CurrentDomain.BaseDirectory
         };
     AddFile(Path.GetFileNameWithoutExtension(fileName), configuration);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Add a new log file
 /// </summary>
 /// <param name="fileName">Target file without path (Path is configured in <paramref name="configuration"/>).</param>
 /// <param name="configuration">Configuration used to control how entries should be written to the file</param>
 public void AddFile(string fileName, FileConfiguration configuration)
 {
     Targets.Add(new PaddedFileTarget(fileName, configuration));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds the file.
        /// </summary>
        /// <param name="fileName">Absolute or application relative path to the log file</param>
        /// <remarks>
        /// Will used the default settings for <see cref="FileConfiguration"/>.
        /// </remarks>
        public static void AddFile(string fileName)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(fileName));
            var path = Path.IsPathRooted(fileName)
                           ? Path.GetDirectoryName(fileName)
                           : AppDomain.CurrentDomain.BaseDirectory;

            if (string.IsNullOrEmpty(path))
                throw new InvalidOperationException("Expected AppDomain.CurrentDomain.BaseDirectory to be set.");

            var configuration = new FileConfiguration
                                    {
                                        Path = path
                                    };

            fileName = Path.GetFileNameWithoutExtension(fileName);
            if (string.IsNullOrEmpty(fileName))
                throw new InvalidOperationException(string.Format("fileName '{0}' was not specified correctly.", fileName));
            AddFile(fileName, configuration);
        }
 /// <summary>
 /// Add a file logger
 /// </summary>
 /// <param name="name">Target alias</param>
 /// <param name="config">Custom configuration</param>
 /// <returns>Target configuration</returns>
 public FluentTargetConfiguration FileLogger(string name, FileConfiguration config)
 {
     Add(new FileTarget(name, config));
     return _configuration;
 }
 /// <summary>
 /// File logger which uses columns for each property being logged.
 /// </summary>
 /// <param name="name">Filename without extension and path</param>
 /// <returns>Target configuration</returns>
 public FluentTargetConfiguration PaddedFileLogger(string name)
 {
     var config = new FileConfiguration
         {
             Path = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + "\\logs\\",
             DaysToKeep = 7
         };
     Add(new PaddedFileTarget(name, config));
     return _configuration;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PaddedFileTarget"/> class.
 /// </summary>
 /// <param name="name">Unique name for this target. Could be the file name</param>
 /// <param name="configuration">The configuration.</param>
 public PaddedFileTarget(string name, FileConfiguration configuration)
     : base(name, configuration)
 {
     Contract.Requires<ArgumentNullException>(!String.IsNullOrEmpty(name));
     Contract.Requires<ArgumentNullException>(configuration != null);
 }
        public FluentTargetConfiguration PaddedFileLogger(string name)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(name));

            var config = new FileConfiguration
                             {
                                 Path = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + "\\logs\\",
                                 DaysToKeep = 7
                             };
            Add(new PaddedFileTarget(name, config));
            return _configuration;
        }
        public FluentTargetConfiguration PaddedFileLogger(string name, FileConfiguration config)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(name));
            Contract.Requires<ArgumentNullException>(config != null);

            Add(new PaddedFileTarget(name, config));
            return _configuration;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileWriter"/> class.
 /// </summary>
 /// <param name="name">Fle name.</param>
 /// <param name="configuration">The configuration.</param>
 public FileWriter(string name, FileConfiguration configuration)
 {
     _name = name;
     _configuration = configuration;
     _logDate = DateTime.Today;
 }