public void PopulateDictionaryFilledCorrectly() { provider = new DebugInformationProvider(); provider.PopulateDictionary(dictionary); Assert.IsTrue(dictionary.Count > 0, "Dictionary contains no items"); AssertUtilities.AssertStringDoesNotContain(dictionary[SR.DebugInfo_StackTrace] as string, SR.ExtendedPropertyError(""), "Stack trace"); }
public void PopulateDictionaryFilledWithSecurityException() { provider = new DebugInformationProvider(new MockDebugUtilsThrowsSecurityException()); provider.PopulateDictionary(dictionary); Assert.IsTrue(dictionary.Count > 0, "Dictionary contains no items"); Assert.AreEqual(dictionary[SR.DebugInfo_StackTrace], SR.ExtendedPropertyError(SR.DebugInfo_StackTraceSecurityException)); }
public void PopulateDictionaryFilledWithGenericException() { provider = new DebugInformationProvider(new MockDebugUtilsThrowsNonSecurityException()); provider.PopulateDictionary(dictionary); Assert.IsTrue(dictionary.Count > 0, "Dictionary contains no items"); Assert.AreEqual(dictionary[Resources.DebugInfo_StackTrace], String.Format(Resources.ExtendedPropertyError, Resources.DebugInfo_StackTraceException)); }
public void PopulateDictionaryFilledCorrectly() { provider = new DebugInformationProvider(); provider.PopulateDictionary(dictionary); Assert.IsTrue(dictionary.Count > 0, "Dictionary contains no items"); AssertUtilities.AssertStringDoesNotContain(dictionary[Resources.DebugInfo_StackTrace] as string, String.Format(Resources.ExtendedPropertyError, ""), "Stack trace"); }
private static Dictionary <string, object> BuildDebugInfoWithStack(string methodName) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("Method", methodName); DebugInformationProvider informationHelper = new DebugInformationProvider(); informationHelper.PopulateDictionary(dictionary); return(dictionary); }
private void Application_Error(object sender, EventArgs e) { HttpContext ctx = HttpContext.Current; HttpRequest request = ctx.Request; HttpApplication application = (HttpApplication)sender; Exception ex = application.Server.GetLastError().GetBaseException(); // Use log write factory to load from app.config LogWriterFactory logWriterFactory = new LogWriterFactory(); // Create the LogWrite instance LogWriter logWriter = logWriterFactory.Create(); // Create debug provider var extendedInfo = new Dictionary <string, object>(); var debug = new DebugInformationProvider(); debug.PopulateDictionary(extendedInfo); // Create the Log Entry var logEntry = new LogEntry { Message = "This is an error message", Categories = new List <string> { "Debug" }, ExtendedProperties = extendedInfo }; // Prepare the trace manager TraceManager traceManager = new TraceManager(logWriter); // Log // checking app.config "tracingEnabled" - <loggingConfiguration name="" tracingEnabled="true"> if (logWriter.IsLoggingEnabled()) { logWriter.Write("This is a Demo log message", "Demo"); logWriter.Write("This is an application error", "Error"); logWriter.Write("This is a general log message"); using (traceManager.StartTrace("Debug")) { logWriter.Write(logEntry); } } ExceptionPolicy.HandleException(ex, "GlobalExceptionLogger"); ctx.Server.ClearError(); ctx.Response.Write(Logger.IsLoggingEnabled()); ctx.Response.Write(Logger.ShouldLog(logEntry)); ctx.Response.Write(logEntry.Categories.Contains("Debug")); }
static void Main(string[] args) { // Option to programatically create logging configuration // Create trace listeners // FlatFileTraceListener flatFileTraceListener = new FlatFileTraceListener("logging.txt"); // Build Configuration // LoggingConfiguration config = new LoggingConfiguration(); // config.AddLogSource("General", SourceLevels.All, true); // Configure the LogWriter instance // LogWriter defaultWriter = new LogWriter(config); // Use log write factory to load from app.config LogWriterFactory logWriterFactory = new LogWriterFactory(); // Create the LogWrite instance LogWriter logWriter = logWriterFactory.Create(); // Create debug provider var extendedInfo = new Dictionary <string, object>(); var debug = new DebugInformationProvider(); debug.PopulateDictionary(extendedInfo); // Create the Log Entry var logEntry = new LogEntry { Message = "This is an error message", Categories = new List <string> { "Debug" }, ExtendedProperties = extendedInfo }; // Prepare the trace manager TraceManager traceManager = new TraceManager(logWriter); // Log // checking app.config "tracingEnabled" - <loggingConfiguration name="" tracingEnabled="true"> if (logWriter.IsLoggingEnabled()) { logWriter.Write("This is a Demo log message", "Demo"); logWriter.Write("This is an application error", "Error"); logWriter.Write("This is a general log message"); using (traceManager.StartTrace("Debug")) { logWriter.Write(logEntry); } } }
public CompilationBuilder UseDebugInfoProvider(DebugInformationProvider provider) { _debugInformationProvider = provider; return(this); }
static void ShowDetailsAndAddExtraInfo(LogEntry entry) { // Display information about the Trace Sources and Listeners for this LogEntry. IEnumerable <LogSource> sources = defaultWriter.GetMatchingTraceSources(entry); foreach (LogSource source in sources) { Console.WriteLine("Log Source name: '{0}'", source.Name); foreach (TraceListener listener in source.Listeners) { Console.WriteLine(" - Listener name: '{0}'", listener.Name); } } // Check if any filters will block this LogEntry. // This approach allows you to check for specific types of filter. // If there are no filters of the specified type configured, the GetFilter // method returns null, so check this before calling the ShouldLog method. CategoryFilter catFilter = defaultWriter.GetFilter <CategoryFilter>(); if (null == catFilter || catFilter.ShouldLog(entry.Categories)) { Console.WriteLine("Category Filter(s) will not block this LogEntry."); } else { Console.WriteLine("A Category Filter will block this LogEntry."); } PriorityFilter priFilter = defaultWriter.GetFilter <PriorityFilter>(); if (null == priFilter || priFilter.ShouldLog(entry.Priority)) { Console.WriteLine("Priority Filter(s) will not block this LogEntry."); } else { Console.WriteLine("A Priority Filter will block this LogEntry."); } // Alternatively, a simple approach can be used to check for any type of filter if (defaultWriter.ShouldLog(entry)) { Console.WriteLine("This LogEntry will not be blocked due to configuration settings."); // Create the additional context information to add to the LogEntry. Checking that // the LogEntry will not be blocked first minimizes the performance impact. Dictionary <string, object> dict = new Dictionary <string, object>(); // Use the information helper classes to get information about the environment and add it to the dictionary. DebugInformationProvider debugHelper = new DebugInformationProvider(); debugHelper.PopulateDictionary(dict); Console.WriteLine("Added the current stack trace to the Log Entry."); ManagedSecurityContextInformationProvider infoHelper = new ManagedSecurityContextInformationProvider(); infoHelper.PopulateDictionary(dict); Console.WriteLine("Added current identity name, authentication type, and status to the Log Entry."); UnmanagedSecurityContextInformationProvider secHelper = new UnmanagedSecurityContextInformationProvider(); secHelper.PopulateDictionary(dict); Console.WriteLine("Added the current user name and process account name to the Log Entry."); ComPlusInformationProvider comHelper = new ComPlusInformationProvider(); comHelper.PopulateDictionary(dict); Console.WriteLine("Added COM+ IDs and caller account information to the Log Entry."); // Get any other information you require and add it to the dictionary. string configInfo = File.ReadAllText(@"..\..\App.config"); dict.Add("Config information", configInfo); Console.WriteLine("Added information about the configuration of the application to the Log Entry."); // Set the dictionary in the LogEntry and write it using the default LogWriter. entry.ExtendedProperties = dict; defaultWriter.Write(entry); Console.WriteLine("LogEntry written to configured trace listeners."); Console.WriteLine(); } else { Console.WriteLine("This LogEntry will be blocked due to configuration settings."); } }