|
| 1 | +// <auto-generated /> |
| 2 | + |
| 3 | +namespace DotNetOpenAuth.Loggers { |
| 4 | + using System; |
| 5 | + using System.Globalization; |
| 6 | + using System.IO; |
| 7 | + using System.Reflection; |
| 8 | + |
| 9 | + internal class NLogLogger : ILog { |
| 10 | + private NLog.Logger nLogLogger; |
| 11 | + |
| 12 | + private NLogLogger(NLog.Logger logger) { |
| 13 | + this.nLogLogger = logger; |
| 14 | + } |
| 15 | + |
| 16 | + #region ILog Members |
| 17 | + |
| 18 | + public bool IsDebugEnabled { |
| 19 | + get { return this.nLogLogger.IsDebugEnabled; } |
| 20 | + } |
| 21 | + |
| 22 | + public bool IsInfoEnabled { |
| 23 | + get { return this.nLogLogger.IsInfoEnabled; } |
| 24 | + } |
| 25 | + |
| 26 | + public bool IsWarnEnabled { |
| 27 | + get { return this.nLogLogger.IsWarnEnabled; } |
| 28 | + } |
| 29 | + |
| 30 | + public bool IsErrorEnabled { |
| 31 | + get { return this.nLogLogger.IsErrorEnabled; } |
| 32 | + } |
| 33 | + |
| 34 | + public bool IsFatalEnabled { |
| 35 | + get { return this.nLogLogger.IsFatalEnabled; } |
| 36 | + } |
| 37 | + |
| 38 | + #endregion |
| 39 | + |
| 40 | + private static bool IsNLogPresent { |
| 41 | + get { |
| 42 | + try { |
| 43 | + Assembly.Load("NLog"); |
| 44 | + return true; |
| 45 | + } catch (FileNotFoundException) { |
| 46 | + return false; |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + #region ILog methods |
| 52 | + |
| 53 | + public void Debug(object message) { |
| 54 | + this.nLogLogger.Debug(message); |
| 55 | + } |
| 56 | + |
| 57 | + public void Debug(object message, Exception exception) { |
| 58 | + this.nLogLogger.DebugException(String.Format("{0}", message), exception); |
| 59 | + } |
| 60 | + |
| 61 | + public void DebugFormat(string format, params object[] args) { |
| 62 | + this.nLogLogger.Debug(CultureInfo.InvariantCulture, format, args); |
| 63 | + } |
| 64 | + |
| 65 | + public void DebugFormat(string format, object arg0) { |
| 66 | + this.nLogLogger.Debug(format, arg0); |
| 67 | + } |
| 68 | + |
| 69 | + public void DebugFormat(string format, object arg0, object arg1) { |
| 70 | + this.nLogLogger.Debug(format, arg0, arg1); |
| 71 | + } |
| 72 | + |
| 73 | + public void DebugFormat(string format, object arg0, object arg1, object arg2) { |
| 74 | + this.nLogLogger.Debug(format, arg0, arg1, arg2); |
| 75 | + } |
| 76 | + |
| 77 | + public void DebugFormat(IFormatProvider provider, string format, params object[] args) { |
| 78 | + this.nLogLogger.Debug(provider, format, args); |
| 79 | + } |
| 80 | + |
| 81 | + public void Info(object message) { |
| 82 | + this.nLogLogger.Info(message); |
| 83 | + } |
| 84 | + |
| 85 | + public void Info(object message, Exception exception) { |
| 86 | + this.nLogLogger.InfoException(String.Format("{0}", message), exception); |
| 87 | + } |
| 88 | + |
| 89 | + public void InfoFormat(string format, params object[] args) { |
| 90 | + this.nLogLogger.Info(CultureInfo.InvariantCulture, format, args); |
| 91 | + } |
| 92 | + |
| 93 | + public void InfoFormat(string format, object arg0) { |
| 94 | + this.nLogLogger.Info(format, arg0); |
| 95 | + } |
| 96 | + |
| 97 | + public void InfoFormat(string format, object arg0, object arg1) { |
| 98 | + this.nLogLogger.Info(format, arg0, arg1); |
| 99 | + } |
| 100 | + |
| 101 | + public void InfoFormat(string format, object arg0, object arg1, object arg2) { |
| 102 | + this.nLogLogger.Info(format, arg0, arg1, arg2); |
| 103 | + } |
| 104 | + |
| 105 | + public void InfoFormat(IFormatProvider provider, string format, params object[] args) { |
| 106 | + this.nLogLogger.Info(provider, format, args); |
| 107 | + } |
| 108 | + |
| 109 | + public void Warn(object message) { |
| 110 | + this.nLogLogger.Warn(message); |
| 111 | + } |
| 112 | + |
| 113 | + public void Warn(object message, Exception exception) { |
| 114 | + this.nLogLogger.Warn(String.Format("{0}", message), exception); |
| 115 | + } |
| 116 | + |
| 117 | + public void WarnFormat(string format, params object[] args) { |
| 118 | + this.nLogLogger.Warn(CultureInfo.InvariantCulture, format, args); |
| 119 | + } |
| 120 | + |
| 121 | + public void WarnFormat(string format, object arg0) { |
| 122 | + this.nLogLogger.Warn(format, arg0); |
| 123 | + } |
| 124 | + |
| 125 | + public void WarnFormat(string format, object arg0, object arg1) { |
| 126 | + this.nLogLogger.Warn(format, arg0, arg1); |
| 127 | + } |
| 128 | + |
| 129 | + public void WarnFormat(string format, object arg0, object arg1, object arg2) { |
| 130 | + this.nLogLogger.Warn(format, arg0, arg1, arg2); |
| 131 | + } |
| 132 | + |
| 133 | + public void WarnFormat(IFormatProvider provider, string format, params object[] args) { |
| 134 | + this.nLogLogger.Warn(provider, format, args); |
| 135 | + } |
| 136 | + |
| 137 | + public void Error(object message) { |
| 138 | + this.nLogLogger.Error(message); |
| 139 | + } |
| 140 | + |
| 141 | + public void Error(object message, Exception exception) { |
| 142 | + this.nLogLogger.Error(String.Format("{0}", message), exception); |
| 143 | + } |
| 144 | + |
| 145 | + public void ErrorFormat(string format, params object[] args) { |
| 146 | + this.nLogLogger.Error(CultureInfo.InvariantCulture, format, args); |
| 147 | + } |
| 148 | + |
| 149 | + public void ErrorFormat(string format, object arg0) { |
| 150 | + this.nLogLogger.Error(format, arg0); |
| 151 | + } |
| 152 | + |
| 153 | + public void ErrorFormat(string format, object arg0, object arg1) { |
| 154 | + this.nLogLogger.Error(format, arg0, arg1); |
| 155 | + } |
| 156 | + |
| 157 | + public void ErrorFormat(string format, object arg0, object arg1, object arg2) { |
| 158 | + this.nLogLogger.Error(format, arg0, arg1, arg2); |
| 159 | + } |
| 160 | + |
| 161 | + public void ErrorFormat(IFormatProvider provider, string format, params object[] args) { |
| 162 | + this.nLogLogger.Error(provider, format, args); |
| 163 | + } |
| 164 | + |
| 165 | + public void Fatal(object message) { |
| 166 | + this.nLogLogger.Fatal(message); |
| 167 | + } |
| 168 | + |
| 169 | + public void Fatal(object message, Exception exception) { |
| 170 | + this.nLogLogger.Fatal(String.Format("{0}", message), exception); |
| 171 | + } |
| 172 | + |
| 173 | + public void FatalFormat(string format, params object[] args) { |
| 174 | + this.nLogLogger.Fatal(CultureInfo.InvariantCulture, format, args); |
| 175 | + } |
| 176 | + |
| 177 | + public void FatalFormat(string format, object arg0) { |
| 178 | + this.nLogLogger.Fatal(format, arg0); |
| 179 | + } |
| 180 | + |
| 181 | + public void FatalFormat(string format, object arg0, object arg1) { |
| 182 | + this.nLogLogger.Fatal(format, arg0, arg1); |
| 183 | + } |
| 184 | + |
| 185 | + public void FatalFormat(string format, object arg0, object arg1, object arg2) { |
| 186 | + this.nLogLogger.Fatal(format, arg0, arg1, arg2); |
| 187 | + } |
| 188 | + |
| 189 | + public void FatalFormat(IFormatProvider provider, string format, params object[] args) { |
| 190 | + this.nLogLogger.Fatal(provider, format, args); |
| 191 | + } |
| 192 | + |
| 193 | + #endregion |
| 194 | + |
| 195 | + /// <summary> |
| 196 | + /// Returns a new NLog logger if it exists, or returns null if the assembly cannot be found. |
| 197 | + /// </summary> |
| 198 | + /// <returns>The created <see cref="ILog"/> instance.</returns> |
| 199 | + internal static ILog Initialize(string name) { |
| 200 | + try { |
| 201 | + return IsNLogPresent ? CreateLogger(name) : null; |
| 202 | + } catch (FileLoadException) { |
| 203 | + // wrong NLog.dll version |
| 204 | + return null; |
| 205 | + } catch (TargetInvocationException) { |
| 206 | + // Thrown due to some security issues on .NET 4.5. |
| 207 | + return null; |
| 208 | + } catch (TypeLoadException) { |
| 209 | + // Thrown by mono (http://stackoverflow.com/questions/10805773/error-when-pushing-dotnetopenauth-to-staging-or-production-environment) |
| 210 | + return null; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + /// <summary> |
| 215 | + /// Creates the NLogLogger. Call ONLY after NLog.dll is known to be present. |
| 216 | + /// </summary> |
| 217 | + /// <returns>The created <see cref="ILog"/> instance.</returns> |
| 218 | + private static ILog CreateLogger(string name) { |
| 219 | + return new NLogLogger(NLog.LogManager.GetLogger(name)); |
| 220 | + } |
| 221 | + } |
| 222 | +} |
0 commit comments