//
// TraceSource.cs
//
-// Author:
+// Authors:
// Atsushi Enomoto <atsushi@ximian.com>
+// Marek Safar (marek.safar@gmail.com)
//
// Copyright (C) 2007 Novell, Inc.
-//
-
+// Copyright 2013 Xamarin Inc
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
{
}
- public TraceSource (string name, SourceLevels sourceLevels)
+ public TraceSource (string name, SourceLevels defaultLevel)
{
if (name == null)
throw new ArgumentNullException ("name");
+ if (name.Length == 0)
+ throw new ArgumentException ("name");
+
Hashtable sources = DiagnosticsConfiguration.Settings ["sources"] as Hashtable;
TraceSourceInfo info = sources != null ? sources [name] as TraceSourceInfo : null;
source_switch = new SourceSwitch (name);
- if (info == null)
+ if (info == null) {
listeners = new TraceListenerCollection ();
- else {
+ source_switch.Level = defaultLevel;
+ } else {
source_switch.Level = info.Levels;
listeners = info.Listeners;
}
new TraceSource (null);
}
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ConstructorEmpty ()
+ {
+ new TraceSource ("");
+ }
+
[Test]
public void DefaultValues ()
{
TraceSource ts = new TraceSource ("foo");
ts.Switch = null;
}
+
+ [Test]
+ public void SwitchLevel ()
+ {
+ TraceSource s = new TraceSource ("Source1");
+ Assert.AreEqual (SourceLevels.Off, s.Switch.Level, "#1");
+
+ s = new TraceSource("Source2", SourceLevels.All);
+ Assert.AreEqual (SourceLevels.All, s.Switch.Level, "#2");
+
+ s = new TraceSource("Source3");
+ s.Switch.Level = SourceLevels.All;
+ Assert.AreEqual (SourceLevels.All, s.Switch.Level, "#3");
+ }
}
}