示例#1
0
        private void InitLogger()
        {
            // create the file logger
            Logger fileLogger = new FileLogger(
                Server.MapPath(@"~\Logs\logfile.log"));

#if DEBUG
            fileLogger.SeverityThreshold = LogSeverity.Info;
#else
            fileLogger.SeverityThreshold = LogSeverity.Status;     
#endif

            Logger.AddLogger("File", fileLogger);
        }
示例#2
0
        public static void InitLogger()
        {
            // create the file logger
// ReSharper disable UseObjectOrCollectionInitializer
            Logger fileLogger = new FileLogger(
// ReSharper restore UseObjectOrCollectionInitializer
                HostingEnvironment.MapPath(@"~\Logs\logfile.log"));
            
            #if DEBUG            
            fileLogger.SeverityThreshold = LogSeverity.Info;
            #else
            fileLogger.SeverityThreshold = LogSeverity.Status;     
            #endif
            
            Logger.AddLogger("File", fileLogger);
        }
示例#3
0
 /// <summary>
 /// Check file logger.
 /// </summary>
 /// <param name="fileLogger">
 /// The file logger.
 /// </param>
 /// <returns>
 /// The check file logger.
 /// </returns>
 private static bool CheckFileLogger(FileLogger fileLogger)
 {
     return fileLogger.FileName != string.Empty;
 }
示例#4
0
 /// <summary>
 /// The log file.
 /// </summary>
 /// <param name="severity">
 /// The severity.
 /// </param>
 /// <param name="fileLogger">
 /// The file logger.
 /// </param>
 /// <param name="catagory">
 /// The catagory.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 private static void LogFile(LogSeverity severity, FileLogger fileLogger, string catagory, string message)
 {
     if (CheckFileLogger(fileLogger))
     {
         fileLogger.Log(severity, catagory, message);
     }
 }
示例#5
0
        private static Logger Configure(CompositeLogger aLogger, ConfigLogger aConfigLogger, CompositeLoggerElement aCompLoggerElement)
        {
            Configure((Logger)aLogger, aConfigLogger, aCompLoggerElement);

            foreach (CompositeLoggerElement element in aCompLoggerElement.CompositeLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = new CompositeLogger();
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));
                }

            foreach (FileLoggerElement element in aCompLoggerElement.FileLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = new FileLogger(element.FileName);
                    logger.FileName = element.FileName;
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));//, section));
                }

            foreach (RollingDateFileLoggerElement element in aCompLoggerElement.RollingDateFileLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = RollingFileLogger.NewRollingDateFileLogger(element.FormattedFileName);
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));//, section));
                }

            foreach (RollingSizeFileLoggerElement element in aCompLoggerElement.RollingSizeFileLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = RollingFileLogger.NewRollingSizeFileLogger(element.FileName, element.MaxSize);
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));//, section));
                }

            foreach (EmailLoggerElement element in aCompLoggerElement.EmailLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = new EmailLogger(new System.Net.Mail.SmtpClient(element.SmtpHost), element.From, element.To, element.Subject);
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));//, section));
                }

            foreach (SocketLoggerElement element in aCompLoggerElement.SocketLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = new SerialSocketLogger(element.Host, element.Port);
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));//, section));
                }

            foreach(ConsoleLoggerElement element in aCompLoggerElement.ConsoleLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = TextWriterLogger.NewConsoleLogger();
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));
                }

            foreach(EventLogLoggerElement element in aCompLoggerElement.EventLogLoggers)
                if (element.IsConfiguredForThisMachine())
                {
                    var logger = new EventLogLogger(new System.Diagnostics.EventLog(element.LogName, Environment.MachineName, aConfigLogger.Application));
                    aLogger.AddLogger(element.Name, Configure(logger, Instance, element));
                }

            return aLogger;
        }