Ejemplo n.º 1
0
 public void Enable(LogLevel logLevel)
 {
     lock (this)
     {
         // Set the logging level
         Level = logLevel;
         // Setup (or reinitialise) the target map
         if (m_targets != null)
         {
             // Close any open files
             foreach (LogTarget target in m_targets.Values)
             {
                 if (target.m_output != null)
                 {
                     target.m_output.Close();
                 }
             }
             m_targets.Clear();
         }
         else
         {
             m_targets = new Dictionary <LogLevel, LogTarget>();
         }
         // Set up the targets
         FileSystem fs = (FileSystem)Locator.Current.GetService <IFolder>();
         fs = (FileSystem)fs.OpenFolder(FileSystem.LogFolder);
         string       logFile    = Path.Combine(fs.BasePath, String.Format("senshub-{0:yyyy-MM-dd}.log", DateTime.Now));
         StreamWriter output     = new StreamWriter(File.Open(logFile, FileMode.Append, FileAccess.Write, FileShare.Read));
         IMessageBus  messageBus = Locator.Current.GetService <IMessageBus>();
         ITopic       logBase    = messageBus.Private.Create("server/notifications");
         foreach (LogLevel level in Enum.GetValues(typeof(LogLevel)))
         {
             if (level < logLevel)
             {
                 continue;
             }
             LogTarget target = new LogTarget();
             target.m_output = output;
             if (level >= LogLevel.Warn)
             {
                 target.m_topic = logBase.Create(level.ToString().ToLower() + "s");
             }
             m_targets.Add(level, target);
         }
         m_lastLogOpen = DateTime.Now;
     }
 }