-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from veeman/feature/log4net-optional
Make log4net library optional
- Loading branch information
Showing
18 changed files
with
261 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="log4net" version="2.0.3" targetFramework="net40" /> | ||
<package id="OpenTK" version="1.1.1589.5942" targetFramework="net40" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// | ||
// DefaultLogImpl.cs | ||
// | ||
// Copyright (C) 2018 OpenTK | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
// | ||
|
||
using System; | ||
using log4net; | ||
using log4net.Core; | ||
|
||
namespace ObjectTK.Logging | ||
{ | ||
public class DefaultLogImpl : IObjectTKLogger | ||
{ | ||
protected virtual Type ThisDeclaringType => typeof(DefaultLogImpl); | ||
protected ILogger _logger => _log.Logger; | ||
|
||
protected readonly ILog _log; | ||
|
||
public DefaultLogImpl(ILog logger) | ||
{ | ||
_log = logger; | ||
} | ||
|
||
public bool IsFatalEnabled => _log.IsFatalEnabled; | ||
|
||
public bool IsWarnEnabled => _log.IsWarnEnabled; | ||
|
||
public bool IsInfoEnabled => _log.IsInfoEnabled; | ||
|
||
public bool IsDebugEnabled => _log.IsDebugEnabled; | ||
|
||
public bool IsErrorEnabled => _log.IsErrorEnabled; | ||
|
||
private void Log(Level level, object message, Exception exception = null) | ||
{ | ||
if (!_logger.IsEnabledFor(level)) return; | ||
_logger.Log(ThisDeclaringType, level, message, exception); | ||
} | ||
|
||
private void LogFormat(Level level, IFormatProvider provider, string format, params object[] args) | ||
{ | ||
if (!_logger.IsEnabledFor(level)) return; | ||
|
||
var message = (provider == null) ? | ||
string.Format(format, args) : | ||
string.Format(provider, format, args); | ||
|
||
_logger.Log(ThisDeclaringType, level, message, null); | ||
} | ||
|
||
private void LogFormat(Level level, string format, params object[] args) | ||
{ | ||
LogFormat(null, format, args); | ||
} | ||
|
||
public void Debug(object message, Exception exception = null) | ||
{ | ||
Log(Level.Debug, message); | ||
} | ||
|
||
public void DebugFormat(IFormatProvider provider, string format, params object[] args) | ||
{ | ||
LogFormat(Level.Debug, provider, format, args); | ||
} | ||
|
||
public void DebugFormat(string format, params object[] args) | ||
{ | ||
LogFormat(Level.Debug, null, format, args); | ||
} | ||
|
||
public void Error(object message, Exception exception = null) | ||
{ | ||
Log(Level.Error, message); | ||
} | ||
|
||
public void ErrorFormat(IFormatProvider provider, string format, params object[] args) | ||
{ | ||
LogFormat(Level.Error, provider, format, args); | ||
} | ||
|
||
public void ErrorFormat(string format, params object[] args) | ||
{ | ||
LogFormat(Level.Error, null, format, args); | ||
} | ||
|
||
public void Fatal(object message, Exception exception = null) | ||
{ | ||
Log(Level.Fatal, message); | ||
} | ||
|
||
public void FatalFormat(IFormatProvider provider, string format, params object[] args) | ||
{ | ||
LogFormat(Level.Fatal, provider, format, args); | ||
} | ||
|
||
public void FatalFormat(string format, params object[] args) | ||
{ | ||
LogFormat(Level.Fatal, null, format, args); | ||
} | ||
|
||
public void Info(object message, Exception exception = null) | ||
{ | ||
Log(Level.Info, message); | ||
} | ||
|
||
public void InfoFormat(IFormatProvider provider, string format, params object[] args) | ||
{ | ||
LogFormat(Level.Info, provider, format, args); | ||
} | ||
|
||
public void InfoFormat(string format, params object[] args) | ||
{ | ||
LogFormat(Level.Info, null, format, args); | ||
} | ||
|
||
public void Warn(object message, Exception exception = null) | ||
{ | ||
Log(Level.Warn, message); | ||
} | ||
|
||
public void WarnFormat(IFormatProvider provider, string format, params object[] args) | ||
{ | ||
LogFormat(Level.Warn, provider, format, args); | ||
} | ||
|
||
public void WarnFormat(string format, params object[] args) | ||
{ | ||
LogFormat(Level.Warn, null, format, args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// IObjectTKLogger.cs | ||
// | ||
// Copyright (C) 2018 OpenTK | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ObjectTK.Logging | ||
{ | ||
public interface IObjectTKLogger | ||
{ | ||
bool IsFatalEnabled { get; } | ||
bool IsWarnEnabled { get; } | ||
bool IsInfoEnabled { get; } | ||
bool IsDebugEnabled { get; } | ||
bool IsErrorEnabled { get; } | ||
|
||
void Debug(object message, Exception exception = null); | ||
void DebugFormat(IFormatProvider provider, string format, params object[] args); | ||
void DebugFormat(string format, params object[] args); | ||
|
||
void Error(object message, Exception exception = null); | ||
void ErrorFormat(IFormatProvider provider, string format, params object[] args); | ||
void ErrorFormat(string format, params object[] args); | ||
|
||
void Fatal(object message, Exception exception = null); | ||
void FatalFormat(IFormatProvider provider, string format, params object[] args); | ||
void FatalFormat(string format, params object[] args); | ||
|
||
void Info(object message, Exception exception = null); | ||
void InfoFormat(IFormatProvider provider, string format, params object[] args); | ||
void InfoFormat(string format, params object[] args); | ||
|
||
void Warn(object message, Exception exception = null); | ||
void WarnFormat(IFormatProvider provider, string format, params object[] args); | ||
void WarnFormat(string format, params object[] args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// LogFactory.cs | ||
// | ||
// Copyright (C) 2018 OpenTK | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
// | ||
|
||
using System; | ||
using System.IO; | ||
using log4net; | ||
|
||
namespace ObjectTK.Logging | ||
{ | ||
public static class LogFactory | ||
{ | ||
public static readonly bool IsAvailable = File.Exists(AppDomain.CurrentDomain.BaseDirectory + "log4net.dll"); | ||
|
||
static IObjectTKLogger CreateLogger(Type type) | ||
{ | ||
var logger = LogManager.GetLogger(type); | ||
return logger != null ? new DefaultLogImpl(logger) : null; | ||
} | ||
|
||
public static IObjectTKLogger GetLogger(Type type) | ||
{ | ||
return IsAvailable ? CreateLogger(type) : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.