using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using log4net.Appender; using log4net.Core; using Microsoft.Practices.ServiceLocation; using Taloyhtio.GeneralSSO.Server.CodeFiles.Common; using Taloyhtio.GeneralSSO.Server.CodeFiles.Entities; using Taloyhtio.GeneralSSO.Server.CodeFiles.Repositories; namespace Taloyhtio.GeneralSSO.Server.CodeFiles.Services.Impl { public class Logger : AppenderSkeleton, ILogger { private ILogRepository logRepository; public Logger() { this.logRepository = ServiceLocator.Current.GetInstance(); ; } public void Log(EventType type, string component, string msg) { try { var logRecord = new Log { Component = component, Created = DateTime.Now, EventType = type, ThreadId = Thread.CurrentThread.ManagedThreadId, Message = msg }; this.logRepository.Save(logRecord); } catch { } } public void Info(string component, string msg) { this.Log(EventType.Info, component, msg); } public void Warn(string component, string msg) { this.Log(EventType.Warn, component, msg); } public void Error(string component, string msg) { this.Log(EventType.Error, component, msg); } public void Error(string component, Exception x) { this.Log(EventType.Warn, component, x.ToInfo()); } protected override void Append(LoggingEvent e) { try { if (e == null) { return; } var type = this.getType(e.Level); this.Log(type, Constants.LogComponents.DOTNETOPENAUTH, base.RenderLoggingEvent(e)); } catch { } } private EventType getType(Level level) { if (level == null) { return EventType.Info; } switch (level.Name) { case "DEBUG": case "INFO": return EventType.Info; case "WARN": return EventType.Warn; case "ERROR": case "FATAL": return EventType.Error; default: return EventType.Info; } } } }