/// <summary> /// Creates a new ToffeeServer. /// </summary> /// <param name="configuration">The configuration to use for this server.</param> public ToffeeServer(ToffeeServerConfiguration configuration, LoggerCategory category = null) { // Create the TCP listener Listener = new TcpListener(new IPEndPoint(IPAddress.Any, configuration.Port)); Listening = false; // Set the properties of this server depending on the values in the configuration Port = configuration.Port; MaximumConnections = configuration.MaximumConnections; ForceEncryption = configuration.ForceEncryption; EncryptionKey = configuration.EncryptionKey; // Sanity check for encryption if ((ForceEncryption) && (EncryptionKey == 0x00)) { Log?.Warning("Cannot force encryption, and have no encryption key! Setting 'ForceEncryption' to false."); ForceEncryption = false; } // Create the components if (configuration.Network != null) { Network = ToffeeNetwork.CreateNetwork(configuration.Network.Name, configuration.Network.Suffix); } else { Network = ToffeeNetwork.CreateNetwork(ToffeeNetwork.StandardToffeeNetwork); } SessionManager = new ToffeeSessionManager(this); Log = category; Log?.Info("Created."); }
public TailedRichTextBox(string filename, LoggerCategory loggerCategory, TabPage parentTabPage) { this.filename = filename; ShortcutsEnabled = true; Category = loggerCategory; parentTab = parentTabPage; previousSeekPosition = 0; previousFileSize = 0; ctxMenu = new ContextMenuStrip(); ContextMenuStrip = ctxMenu; if (Category != LoggerCategory.Custom) { ToolStripItem relocateItem = ctxMenu.Items.Add("Correct logfile location"); relocateItem.Click += new EventHandler(relocateItem_Click); } ctxMenu.Items.Add("-"); ToolStripItem searchItem = ctxMenu.Items.Add("Find"); searchItem.Click += new EventHandler(searchItem_Click); ctxMenu.Items.Add("-"); ToolStripItem cfgItem = ctxMenu.Items.Add("Configure search parameters"); cfgItem.Click += new EventHandler(Config_Click); ctxMenu.Items.Add("-"); ToolStripItem clearWindowItem = ctxMenu.Items.Add("Clear window"); clearWindowItem.Click += new EventHandler(clearWindowItem_Click); ToolStripItem clearFileItem = ctxMenu.Items.Add("Delete file"); clearFileItem.Click += new EventHandler(clearFileItem_Click); searchParams = new SearchParameters(); LoadSettings(); }
private static void Detect(out LoggerCategory loggerCategory) { var frame = new StackFrame(2, true); var frameMethod = frame.GetMethod(); var frameType = frameMethod.DeclaringType; if (frameType != null) { var loggerClassAttributes = frameType.GetCustomAttributes(typeof(UseLogger), true) as UseLogger[]; if (loggerClassAttributes != null && loggerClassAttributes.Length != 0) { loggerCategory = loggerClassAttributes[0].LoggerCategory; DebuggerActive = true; } else { loggerCategory = DefaultLoggerCategory; DebuggerActive = false; } } else { loggerCategory = DefaultLoggerCategory; DebuggerActive = false; } }
public TailedRichTextBox(string filename, LoggerCategory loggerCategory, TabPage parentTabPage) { this.filename = filename; ShortcutsEnabled = true; Category = loggerCategory; parentTab = parentTabPage; previousSeekPosition = 0; previousFileSize = 0; ctxMenu = new ContextMenuStrip(); ContextMenuStrip = ctxMenu; if (Category != LoggerCategory.Custom) { ToolStripItem relocateItem = ctxMenu.Items.Add("Correct logfile location"); relocateItem.Click += new EventHandler(relocateItem_Click); } ctxMenu.Items.Add("-"); ToolStripItem searchItem = ctxMenu.Items.Add("Find"); searchItem.Click += new EventHandler(searchItem_Click); ctxMenu.Items.Add("-"); ToolStripItem cfgItem = ctxMenu.Items.Add("Configure search parameters"); cfgItem.Click += new EventHandler(Config_Click); ctxMenu.Items.Add("-"); ToolStripItem clearWindowItem = ctxMenu.Items.Add("Clear window"); clearWindowItem.Click += new EventHandler(clearWindowItem_Click); ToolStripItem clearFileItem = ctxMenu.Items.Add("Delete file"); clearFileItem.Click += new EventHandler(clearFileItem_Click); searchParams = new SearchParameters(); LoadSettings(); }
public static void LogEntry(string message, LoggerCategory category) { InitializeInternalLogViewer(); if (!closed) { viewer.Invoke((MethodInvoker)(() => viewer.InternalLogEntry(message, category))); } }
public static void LogEntry(string message, LoggerCategory category) { InitializeInternalLogViewer(); if (!closed) { viewer.Invoke((MethodInvoker)(() => viewer.InternalLogEntry(message, category))); } }
public static void LogInformation(this ILogger logger, LoggerCategory category, Exception exception, string formatString, params object[] formatParameters) { string str = string.Format((IFormatProvider)logger.Culture, formatString, formatParameters); if (exception != null) { str = LoggerExtensions.BuildExceptionText(exception, str); } logger.Log(TraceEventType.Information, str, category == null ? (string)null : category.Name); }
private static void WriteLog(LoggerCategory categoryName, string source, string errorMessage) { try { _Logger.WriteLog(categoryName, source, errorMessage); } catch (Exception e) { } }
public ToffeeServer(int port, LoggerCategory category = null) { Listener = new TcpListener(new IPEndPoint(IPAddress.Any, port)); Listening = false; Port = port; Network = ToffeeNetwork.CreateNetwork(ToffeeNetwork.StandardToffeeNetwork); SessionManager = new ToffeeSessionManager(this); Log = category; Log?.Info("Created."); }
/// <summary> /// Creates a ToffeeInternalClient instance. /// </summary> public ToffeeInternalClient(ToffeeInternalConfiguration configuration, string roleName = "", LoggerCategory category = null) : base(ToffeeNetwork.StandardToffeeNetwork, 0) { // Properties Configuration = configuration; Role = roleName; Log = category; // If we can, log that this instance was created. Log?.Info("Created internal client."); // Connect to the message director Connect(configuration.Host, configuration.Port); }
private static void Write(string message, LoggerCategory category) { System.Diagnostics.Trace.Write(message + Environment.NewLine, category.ToString()); if (Settings.DisplayDeveloperUI) { // InternalLogViewer.LogEntry(message, category); } var handler = LogWritten; if (handler != null) { handler(message, category); } }
public bool Configure(object config, Logger logger = null) { try { // Get the configuration JObject jConfig = (JObject)config; ClientAgentConfiguration configuration = jConfig.ToObject <ClientAgentConfiguration>(); // Load the network files TdlFile networkFile = new TdlFile(configuration.Network.Namespace, false); foreach (string file in configuration.Network.Files) { if (!networkFile.ParseFile(file)) { Console.WriteLine("Could not find: {0}", file); return(false); } } // Create the logger category LoggerCategory category = logger?.MakeCategory(string.Format("ClientAgent-{0}", UniqueClientAgentIndex)) ?? null; // Sanity checks if (configuration.Internal.ChannelCount != 0) { category.Warning("Internal channel count should not be set manually. Resetting value to maximum connections."); configuration.Internal.ChannelCount = configuration.MaximumConnections; } // Create the server Server = new ClientAgentServer(configuration, networkFile, category); return(true); } catch (JsonException e) { Console.WriteLine(e.Message); return(false); } }
private void AddLogger(string filename, TabControl ctrl) { TabPage tab = new TabPage(Path.GetFileNameWithoutExtension(filename)); LoggerCategory cat = LoggerCategory.MediaPortal; if (ctrl == TVETabCtrl) { cat = LoggerCategory.TvEngine; } else if (ctrl == CustomTabCtrl) { cat = LoggerCategory.Custom; } TailedRichTextBox tr = new TailedRichTextBox(filename, cat, tab); tr.WordWrap = false; tab.Controls.Add(tr); tr.Dock = DockStyle.Fill; ctrl.TabPages.Add(tab); tab.Tag = tr; loggerCollection.Add(tr); }
public bool Configure(object config, Logger logger = null) { try { // Get the configuration JObject jConfig = (JObject)config; MessageDirectorConfiguration configuration = jConfig.ToObject <MessageDirectorConfiguration>(); // Create the server LoggerCategory category = null; if (logger != null) { category = logger.MakeCategory(string.Format("MessageDirector-{0}", UniqueMessageDirectorIndex)); } Server = new MessageDirectorServer(configuration, category); return(true); } catch (JsonException e) { Console.WriteLine(e.Message); return(false); } }
private static void PrintToLog(object obj, LogType logType, LoggerCategory loggerCategory) { if (!DebuggerActive) { Debug.Log(obj.ToString()); return; } var typeString = logType.ToString(); var categoryString = loggerCategory.ToString(); #if UNITY_EDITOR obj = FormatForConsole(ToRGBHex(Palette.GetColorFromCategory(loggerCategory)), ToRGBHex(Palette.GetColorFromType(logType)), categoryString, typeString, obj); #elif UNITY_STANDALONE obj = FormatForFile(DateTime.Now, categoryString, typeString, obj); try { using (var outputStream = System.IO.File.AppendText(System.IO.Path.GetFullPath(string.Format("{0}/../Log.log", Application.dataPath)))) { outputStream.WriteLine(obj); outputStream.Flush(); outputStream.Close(); } } catch (Exception ex) { Debug.LogException(ex); } finally { } #endif Debug.Log(obj); }
internal void InternalLogEntry(string message, LoggerCategory category) { this.loggerListView.Items.Add(new ListViewItem(new[] { category.ToString().Remove(0, 4), DateTime.Now.ToString("HH:mm:ss"), message })); }
public static void BuildRoleLookup(LoggerCategory log = null) { if (RoleLookup != null) { return; } if (log != null) { log.Debug("Building role lookup..."); } #if DEBUG else { Console.WriteLine("Building role lookup..."); } #endif RoleLookup = new Dictionary <string, Type>(); // Get all the currently loaded assemblies Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { // Get the Types in this assembly Type[] types = assembly.Types().ToArray(); foreach (Type type in types) { // Is this Type a ToffeeRole? if (!type.HasAttribute <ToffeeRoleAttribute>()) { continue; } // Does it implement IRole? if (!type.Implements <IRole>()) { throw new ToffeeException("Found proposed role '{0}', but it does not implement IRole.", type.Name); } // Get the attribute ToffeeRoleAttribute attribute = type.Attribute <ToffeeRoleAttribute>(); RoleLookup.Add(attribute.Name, type); if (log != null) { log.Debug("Found role: {0}", attribute.Name); } #if DEBUG else { Console.WriteLine("Found role: {0}", attribute.Name); } #endif } } if (log != null) { log.Debug("Found {0} role(s).", RoleTypes.Length); } #if DEBUG else { Console.WriteLine("Found {0} role(s).", RoleTypes.Length); } #endif }
public UseLogger(LoggerCategory loggerCategory) { LoggerCategory = loggerCategory; }
public Color GetColorFromCategory(LoggerCategory loggerCategory) { return(CategoryPalette[loggerCategory]); }
public static void LogCritical(this ILogger logger, LoggerCategory category, string formatString, params object[] formatParameters) { logger.LogCritical(category, (Exception)null, formatString, formatParameters); }
public ClientAgentServer(ClientAgentConfiguration configuration, TdlFile file, LoggerCategory category) : base(configuration, category) { Configuration = configuration; NetworkFile = file; // Create the internal connection InternalClient = new ToffeeInternalClient(configuration.Internal, "ClientAgent", category); }
internal void InternalLogEntry(string message, LoggerCategory category) { this.loggerListView.Items.Add(new ListViewItem(new[] { category.ToString().Remove(0, 4), DateTime.Now.ToString("HH:mm:ss"), message })); }
public MessageDirectorServer(MessageDirectorConfiguration configuration, LoggerCategory category) : base(configuration, category) { Configuration = configuration; }
/// <summary> /// The <see cref="NullLogger"/> does nothing in this <see cref="ILogger"/> implementation. /// </summary> /// <param name="category">The category the message is used for.</param> /// <param name="messageGenerator"></param> public void Trace(LoggerCategory category, Func <string> messageGenerator) { }
private static void WriteLog(LoggerCategory categoryName, string source, string errorMessage) { SPDiagnosticsCategory category = Current.Areas[DiagnosticAreaName].Categories[categoryName.ToString()]; Current.WriteTrace(0, category, category.TraceSeverity, string.Concat(string.Format("[{0}]", source), " ", errorMessage)); }
public static void LogCritical(this ILogger logger, LoggerCategory category, Exception exception) { logger.LogCritical(category, exception, (string)null, new object[0]); }