Skip to content

Commit

Permalink
Revert "chore: removes logging"
Browse files Browse the repository at this point in the history
This reverts commit 0aa13bd.
  • Loading branch information
sophie authored and sophie-gilbert committed Jan 7, 2025
1 parent 6257083 commit 388ecf7
Show file tree
Hide file tree
Showing 272 changed files with 1,994 additions and 1,439 deletions.
40 changes: 20 additions & 20 deletions FoxTunes.Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public bool Contains(string id)

private void Add(ConfigurationSection section)
{
//Logger.Write(this, LogLevel.Debug, "Adding configuration section: {0} => {1}", section.Id, section.Name);
Logger.Write(this, LogLevel.Debug, "Adding configuration section: {0} => {1}", section.Id, section.Name);
this.Sections.Add(section.Id, section);
}

private void Update(ConfigurationSection section)
{
//Logger.Write(this, LogLevel.Debug, "Updating configuration section: {0} => {1}", section.Id, section.Name);
Logger.Write(this, LogLevel.Debug, "Updating configuration section: {0} => {1}", section.Id, section.Name);
var existing = this.GetSection(section.Id);
existing.Update(section);
}
Expand Down Expand Up @@ -103,10 +103,10 @@ public void Load(string profile)
}
if (!File.Exists(fileName))
{
//Logger.Write(this, LogLevel.Debug, "Configuration file \"{0}\" does not exist.", fileName);
Logger.Write(this, LogLevel.Debug, "Configuration file \"{0}\" does not exist.", fileName);
return;
}
//Logger.Write(this, LogLevel.Debug, "Loading configuration from file \"{0}\".", fileName);
Logger.Write(this, LogLevel.Debug, "Loading configuration from file \"{0}\".", fileName);
this.OnLoading();
try
{
Expand All @@ -121,18 +121,18 @@ public void Load(string profile)
{
//If config was created by a component that is no longer loaded then it will be lost here.
//TODO: Add the config but hide it so it's preserved but not displayed.
//Logger.Write(this, LogLevel.Warn, "Configuration section \"{0}\" no longer exists.", section.Key);
Logger.Write(this, LogLevel.Warn, "Configuration section \"{0}\" no longer exists.", section.Key);
continue;
}
var existing = this.GetSection(section.Key);
try
{
//Logger.Write(this, LogLevel.Debug, "Loading configuration section \"{0}\".", section.Key);
Logger.Write(this, LogLevel.Debug, "Loading configuration section \"{0}\".", section.Key);
restoredElements.AddRange(this.Load(existing, section.Value));
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Warn, "Failed to load configuration section \"{0}\": {1}", existing.Id, e.Message);
Logger.Write(this, LogLevel.Warn, "Failed to load configuration section \"{0}\": {1}", existing.Id, e.Message);
}
}
}
Expand All @@ -142,14 +142,14 @@ public void Load(string profile)
{
continue;
}
//Logger.Write(this, LogLevel.Debug, "Resetting configuration element: \"{0}\".", modifiedElement.Id);
Logger.Write(this, LogLevel.Debug, "Resetting configuration element: \"{0}\".", modifiedElement.Id);
modifiedElement.Reset();
}
Profiles.Profile = profile;
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Warn, "Failed to load configuration: {0}", e.Message);
Logger.Write(this, LogLevel.Warn, "Failed to load configuration: {0}", e.Message);
}
this.OnLoaded();
}
Expand All @@ -163,10 +163,10 @@ protected virtual IEnumerable<ConfigurationElement> Load(ConfigurationSection se
{
//If config was created by a component that is no longer loaded then it will be lost here.
//TODO: Add the config but hide it so it's preserved but not displayed.
//Logger.Write(this, LogLevel.Warn, "Configuration element \"{0}\" no longer exists.", element.Key);
Logger.Write(this, LogLevel.Warn, "Configuration element \"{0}\" no longer exists.", element.Key);
continue;
}
//Logger.Write(this, LogLevel.Debug, "Loading configuration element: \"{0}\".", element.Key);
Logger.Write(this, LogLevel.Debug, "Loading configuration element: \"{0}\".", element.Key);
var existing = section.GetElement(element.Key);
existing.SetPersistentValue(element.Value);
restoredElements.Add(existing);
Expand Down Expand Up @@ -211,7 +211,7 @@ public void Save(string profile)
}
var fileName = Profiles.GetFileName(profile);
this.OnSaving();
//Logger.Write(this, LogLevel.Debug, "Saving configuration to file \"{0}\".", fileName);
Logger.Write(this, LogLevel.Debug, "Saving configuration to file \"{0}\".", fileName);
try
{
//Use a temp file so the settings aren't lost if something goes wrong.
Expand All @@ -226,9 +226,9 @@ public void Save(string profile)
}
Profiles.Profile = profile;
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Warn, "Failed to save configuration: {0}", e.Message);
Logger.Write(this, LogLevel.Warn, "Failed to save configuration: {0}", e.Message);
}
this.OnSaved();
}
Expand All @@ -251,9 +251,9 @@ public void Copy(string profile)
}
Profiles.Profile = profile;
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Warn, "Failed to copy configuration: {0}", e.Message);
Logger.Write(this, LogLevel.Warn, "Failed to copy configuration: {0}", e.Message);
}
}

Expand Down Expand Up @@ -299,9 +299,9 @@ public void Delete(string profile)
}
this.Load();
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Warn, "Failed to delete configuration: {0}", e.Message);
Logger.Write(this, LogLevel.Warn, "Failed to delete configuration: {0}", e.Message);
}
this.OnSaved();
}
Expand Down
18 changes: 13 additions & 5 deletions FoxTunes.Config/Profiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace FoxTunes
{
public static class Profiles
{
private static ILogger Logger
{
get
{
return LogManager.Logger;
}
}

private static readonly string ConfigurationFileName = Path.Combine(
Publication.StoragePath,
"Profiles.txt"
Expand All @@ -32,16 +40,16 @@ public static class Profiles
}
}
}
catch
catch (Exception e)
{
//Logger.Write(typeof(Profiles), LogLevel.Warn, "Failed to read available profiles: {0}", e.Message);
Logger.Write(typeof(Profiles), LogLevel.Warn, "Failed to read available profiles: {0}", e.Message);
}
}
if (!profiles.Contains(Strings.Profiles_Default, StringComparer.OrdinalIgnoreCase))
{
profiles.Insert(0, Strings.Profiles_Default);
}
//Logger.Write(typeof(Profiles), LogLevel.Debug, "Available profiles: {0}", string.Join(", ", profiles));
Logger.Write(typeof(Profiles), LogLevel.Debug, "Available profiles: {0}", string.Join(", ", profiles));
return profiles;
});

Expand Down Expand Up @@ -103,9 +111,9 @@ private static void Update(string profile, bool delete)
}
}
}
catch
catch (Exception e)
{
//Logger.Write(typeof(Profiles), LogLevel.Warn, "Failed to write available profiles: {0}", e.Message);
Logger.Write(typeof(Profiles), LogLevel.Warn, "Failed to write available profiles: {0}", e.Message);
}
_AvailableProfiles.Reset();
}
Expand Down
16 changes: 12 additions & 4 deletions FoxTunes.Config/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace FoxTunes
{
public static class Serializer
{
private static ILogger Logger
{
get
{
return LogManager.Logger;
}
}

public static void Save(Stream stream, IEnumerable<ConfigurationSection> sections)
{
using (var writer = new XmlTextWriter(stream, Encoding.Default))
Expand All @@ -25,12 +33,12 @@ public static void Save(Stream stream, IEnumerable<ConfigurationSection> section
{
continue;
}
//Logger.Write(typeof(Serializer), LogLevel.Trace, "Saving configuration section: \"{0}\".", section.Id);
Logger.Write(typeof(Serializer), LogLevel.Trace, "Saving configuration section: \"{0}\".", section.Id);
writer.WriteStartElement(nameof(ConfigurationSection));
writer.WriteAttributeString(nameof(section.Id), section.Id);
foreach (var element in elements)
{
//Logger.Write(typeof(Serializer), LogLevel.Trace, "Saving configuration element: \"{0}\".", element.Id);
Logger.Write(typeof(Serializer), LogLevel.Trace, "Saving configuration element: \"{0}\".", element.Id);
writer.WriteStartElement(nameof(ConfigurationElement));
writer.WriteAttributeString(nameof(ConfigurationElement.Id), element.Id);
writer.WriteCData(element.GetPersistentValue());
Expand All @@ -53,7 +61,7 @@ public static IEnumerable<KeyValuePair<string, IEnumerable<KeyValuePair<string,
while (reader.IsStartElement(nameof(ConfigurationSection)))
{
var id = reader.GetAttribute(nameof(ConfigurationSection.Id));
//Logger.Write(typeof(Serializer), LogLevel.Trace, "Loading configuration section: \"{0}\".", id);
Logger.Write(typeof(Serializer), LogLevel.Trace, "Loading configuration section: \"{0}\".", id);
reader.ReadStartElement(nameof(ConfigurationSection));
sections.Add(new KeyValuePair<string, IEnumerable<KeyValuePair<string, string>>>(id, Load(reader)));
if (reader.NodeType == XmlNodeType.EndElement && string.Equals(reader.Name, nameof(ConfigurationSection)))
Expand All @@ -75,7 +83,7 @@ private static IEnumerable<KeyValuePair<string, string>> Load(XmlReader reader)
while (reader.IsStartElement(nameof(ConfigurationElement)))
{
var id = reader.GetAttribute(nameof(ConfigurationElement.Id));
//Logger.Write(typeof(Serializer), LogLevel.Trace, "Loading configuration element: \"{0}\".", id);
Logger.Write(typeof(Serializer), LogLevel.Trace, "Loading configuration element: \"{0}\".", id);
reader.ReadStartElement(nameof(ConfigurationElement));
elements.Add(new KeyValuePair<string, string>(id, reader.Value));
reader.Read(); //Done with <![CDATA[
Expand Down
10 changes: 5 additions & 5 deletions FoxTunes.Core.Windows/Behaviours/ExecutionStateBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected virtual void Enable()
this.Timer.Interval = UPDATE_INTERVAL;
this.Timer.Elapsed += this.OnElapsed;
this.Timer.Start();
//Logger.Write(this, LogLevel.Debug, "Power state manager was started.");
Logger.Write(this, LogLevel.Debug, "Power state manager was started.");
}
}

Expand All @@ -43,7 +43,7 @@ protected virtual void Disable()
this.Timer.Elapsed -= this.OnElapsed;
this.Timer.Dispose();
this.Timer = null;
//Logger.Write(this, LogLevel.Debug, "Power state manager was stopped.");
Logger.Write(this, LogLevel.Debug, "Power state manager was stopped.");
}
}

Expand Down Expand Up @@ -113,9 +113,9 @@ protected virtual bool SetThreadExecutionState()
}
return true;
}
catch
catch (Exception e)
{
//Logger.Write(this, LogLevel.Error, "Failed to set thread execution state: {0}", e.Message);
Logger.Write(this, LogLevel.Error, "Failed to set thread execution state: {0}", e.Message);
return false;
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ protected virtual void OnDisposing()

~ExecutionStateBehaviour()
{
//Logger.Write(this, LogLevel.Error, "Component was not disposed: {0}", this.GetType().Name);
Logger.Write(this, LogLevel.Error, "Component was not disposed: {0}", this.GetType().Name);
try
{
this.Dispose(true);
Expand Down
Loading

0 comments on commit 388ecf7

Please sign in to comment.