public void ConstructorTest() { var item = new TraceSwitch("SwitchName", "Description"); item = new TraceSwitch("SwitchName", null); item = new TraceSwitch(null, null); Assert.Equal("", item.DisplayName); }
public void TraceLevelTest(TraceLevel level, bool error, bool warning, bool info, bool verbose) { var item = new TraceSwitch("SwitchName", "Description"); item.Level = level; Assert.Equal(error, item.TraceError); Assert.Equal(warning, item.TraceWarning); Assert.Equal(info, item.TraceInfo); Assert.Equal(verbose, item.TraceVerbose); }
static int Main (string [] args) { TraceSwitch ts = new TraceSwitch ("t", "t"); if (ts.Level != TraceLevel.Error) return 1; Trace.AutoFlush = true; Trace.Write ("WORKS FINE"); return 0; }
public void LevelTest() { var item = new TraceSwitch("SwitchName", "Description", "Error"); Assert.Equal(TraceLevel.Error, item.Level); item.Level = TraceLevel.Info; Assert.Equal(TraceLevel.Info, item.Level); Assert.Throws<ArgumentException>(() => item.Level = (TraceLevel)(TraceLevel.Off - 1)); Assert.Throws<ArgumentException>(() => item.Level = (TraceLevel)(TraceLevel.Verbose + 1)); }
public void ConstructorTest2() { var item = new TraceSwitch("SwitchName", "Description", "Error"); Assert.Equal(TraceLevel.Error, item.Level); item = new TraceSwitch("SwitchName", null, "warning"); Assert.Equal(TraceLevel.Warning, item.Level); item = new TraceSwitch("Name", null, "NO_EXIST"); Assert.Throws<ArgumentException>(() => item.Level); item = new TraceSwitch("Name", null, null); Assert.Throws<ArgumentNullException>(() => item.Level); }
public static void LogWarning(TraceSwitch traceSwitch, Exception ex) { LogError(traceSwitch, ex.ToString()); }
public static void LogWarning(TraceSwitch traceSwitch, string message, object[] args) { if (!traceSwitch.TraceWarning) return; Log(TraceLevel.Warning, message, args); }
public static void LogVerbose(TraceSwitch traceSwitch, string message, object[] args) { if (!traceSwitch.TraceVerbose) return; Log(TraceLevel.Verbose, message, args); }
public static void LogInfo(TraceSwitch traceSwitch, string message, object[] args) { if (!traceSwitch.TraceInfo) return; Log(TraceLevel.Info, message, args); }
public static void LogError(TraceSwitch traceSwitch, Exception ex, NameValueCollection error) { var stringBuilder = new StringBuilder(); foreach (string index in error.Keys) stringBuilder.AppendFormat("{0} : {1}\n", index, error[index]); stringBuilder.Append(ex); LogError(traceSwitch, stringBuilder.ToString()); }
public static void LogError(TraceSwitch traceSwitch, string message, object[] args) { if (!traceSwitch.TraceError) return; Log(TraceLevel.Error, message, args); }
static int Test4 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); #if NET_2_0 && !MONO if (testSwitch1.Level != TraceLevel.Warning) return 1; #else try { Assert.Fail ("#A1:" + testSwitch1.Level); } catch (ConfigurationException ex) { // Required attribute 'value' cannot be empty Assert.IsNull (ex.InnerException, "#A2"); Assert.IsNotNull (ex.Message, "#A3"); Assert.IsTrue (ex.Message.IndexOf ("'value'") != -1, "#A4"); } #endif #if !MONO TraceSwitch testSwitch8 = new TraceSwitch ("testSwitch8", null); #if NET_2_0 try { Assert.Fail ("#B1:" + testSwitch8.Level); } catch (ConfigurationException ex) { // The config value for Switch 'testSwitch8' was invalid Assert.IsNotNull (ex.InnerException, "#B2"); Assert.IsNotNull (ex.Message, "#B3"); Assert.IsTrue (ex.Message.IndexOf ("'testSwitch8'") != -1, "#B4"); // Must specify valid information for parsing in the string ArgumentException ae = ex.InnerException as ArgumentException; Assert.IsNotNull (ae, "#B5"); Assert.IsNull (ae.InnerException, "#B6"); Assert.IsNotNull (ae.Message, "#B7"); } #else if (testSwitch8.Level != TraceLevel.Off) return 1; #endif #endif return 0; }
public static void Info(TraceSwitch traceSwitch, string message, params object[] p) { if(traceSwitch.TraceInfo) { WriteLine(message, p); } }
static int Test2 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); #if NET_2_0 if (testSwitch1.Level != TraceLevel.Off) return 1; TraceSwitch testSwitch8 = new TraceSwitch ("testSwitch8", null); try { Assert.Fail ("#1:" + testSwitch8.Level); } catch (ConfigurationErrorsException ex) { // The config value for Switch 'testSwitch8' was invalid Assert.AreEqual (typeof (ConfigurationErrorsException), ex.GetType (), "#2"); Assert.IsNotNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("'testSwitch8'") != -1, "#5"); ArgumentException ae = ex.InnerException as ArgumentException; Assert.IsNotNull (ae, "#6"); Assert.IsNotNull (ae.Message, "#7"); Assert.IsTrue (ae.Message.IndexOf ("'Invalid'") != -1, "#8"); } #else try { Assert.Fail ("#1:" + testSwitch1.Level); } catch (ConfigurationException ex) { // Error in trace switch 'testSwitch8': The value of a // switch must be integral Assert.AreEqual (typeof (ConfigurationException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("'testSwitch8'") != -1, "#5"); } #endif return 0; }
static int Test1 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); if (testSwitch1.Level != TraceLevel.Verbose) return 1; TraceSwitch testSwitch2 = new TraceSwitch ("testSwitch2", null); if (testSwitch2.Level != TraceLevel.Off) return 2; TraceSwitch testSwitch3 = new TraceSwitch ("testSwitch3", null); if (testSwitch3.Level != TraceLevel.Warning) return 3; TraceSwitch testSwitch4 = new TraceSwitch ("testSwitch4", null); if (testSwitch4.Level != TraceLevel.Info) return 4; TraceSwitch testSwitch5 = new TraceSwitch ("testSwitch5", null); if (testSwitch5.Level != TraceLevel.Verbose) return 5; TraceSwitch testSwitch6 = new TraceSwitch ("testSwitch6", null); if (testSwitch6.Level != TraceLevel.Off) return 6; #if NET_2_0 TraceSwitch testSwitch7 = new TraceSwitch ("testSwitch7", null); if (testSwitch7.Level != TraceLevel.Info) return 7; TraceSwitch testSwitch8 = new TraceSwitch ("testSwitch8", null); if (testSwitch8.Level != TraceLevel.Warning) return 8; #endif TraceSwitch testSwitch9 = new TraceSwitch ("testSwitch9", null); if (testSwitch9.Level != TraceLevel.Off) return 9; BooleanSwitch boolSwitch1 = new BooleanSwitch ("boolSwitch1", null); if (boolSwitch1.Enabled) return 10; BooleanSwitch boolSwitch2 = new BooleanSwitch ("boolSwitch2", null); if (!boolSwitch2.Enabled) return 11; BooleanSwitch boolSwitch3 = new BooleanSwitch ("boolSwitch3", null); if (!boolSwitch3.Enabled) return 12; BooleanSwitch boolSwitch4 = new BooleanSwitch ("boolSwitch4", null); if (boolSwitch4.Enabled) return 13; #if NET_2_0 BooleanSwitch boolSwitch5 = new BooleanSwitch ("boolSwitch5", null); if (!boolSwitch5.Enabled) return 14; BooleanSwitch boolSwitch6 = new BooleanSwitch ("boolSwitch6", null); if (boolSwitch6.Enabled) return 15; SourceSwitch sourceSwitch1 = new SourceSwitch ("sourceSwitch1"); if ((sourceSwitch1.Level & SourceLevels.Critical) == 0) return 16; SourceSwitch sourceSwitch2 = new SourceSwitch ("sourceSwitch2"); if ((sourceSwitch2.Level & SourceLevels.Warning) == 0) return 17; if ((sourceSwitch2.Level & SourceLevels.Error) == 0) return 18; SourceSwitch sourceSwitch3 = new SourceSwitch ("sourceSwitch3"); if (sourceSwitch3.Level != SourceLevels.Off) return 19; #endif return 0; }
static int Test5 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); try { Assert.Fail ("#1:" + testSwitch1.Level); } catch (ConfigurationException ex) { // Unrecognized element 'unexpected' Assert.IsNull (ex.InnerException, "#2"); Assert.IsNotNull (ex.Message, "#3"); #if NET_2_0 || MONO Assert.IsTrue (ex.Message.IndexOf ("'unexpected'") != -1, "#4"); #endif } return 0; }
public static void LogWarning(TraceSwitch traceSwitch, Exception ex, string error) { LogError(traceSwitch, "{0}\n{1}", error, ex.ToString()); }
static SPDataTracer() { tracerSwitch = new TraceSwitch("TraceSwitch", "application trace switch"); }
public static void Error(TraceSwitch traceSwitch, string message, params object[] p) { if(traceSwitch.TraceError) { WriteLine(message, p); } }
static int Test3 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); try { Assert.Fail ("#1:" + testSwitch1.Level); } catch (ConfigurationException ex) { // Required attribute 'value' not found Assert.IsNull (ex.InnerException, "#2"); Assert.IsNotNull (ex.Message, "#3"); Assert.IsTrue (ex.Message.IndexOf ("'value'") != -1, "#4"); } return 0; }
public static void Warning(TraceSwitch traceSwitch, string message, params object[] p) { if(traceSwitch.TraceWarning) { WriteLine(message, p); } }
public static string ToTextAll <TRec>(IEnumerable <TRec> records, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) where TRec : class { if (records == null) { return(null); } if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return(csv.ToString()); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return(csv.ToString()); } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVWriter <TRec>(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Write(records); writer.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }