|
| 1 | +using System; |
| 2 | +using ServiceStack.Logging; |
| 3 | + |
| 4 | +namespace ServiceStack.Logging.NLogger |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Wrapper over the NLog 2.0 beta and above logger |
| 8 | + /// </summary> |
| 9 | + public class NLogLogger : ServiceStack.Logging.ILog |
| 10 | + { |
| 11 | + private readonly NLog.Logger log; |
| 12 | + |
| 13 | + public NLogLogger(string typeName) |
| 14 | + { |
| 15 | + log = NLog.LogManager.GetLogger(typeName); |
| 16 | + } |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// Initializes a new instance of the <see cref="NLogLogger"/> class. |
| 20 | + /// </summary> |
| 21 | + /// <param name="type">The type.</param> |
| 22 | + public NLogLogger(Type type) |
| 23 | + { |
| 24 | + log = NLog.LogManager.GetLogger(type.Name); |
| 25 | + } |
| 26 | + |
| 27 | + public bool IsDebugEnabled { get { return log.IsDebugEnabled; } } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Logs a Debug message. |
| 31 | + /// </summary> |
| 32 | + /// <param name="message">The message.</param> |
| 33 | + public void Debug(object message) |
| 34 | + { |
| 35 | + log.Debug(message); |
| 36 | + } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Logs a Debug message and exception. |
| 40 | + /// </summary> |
| 41 | + /// <param name="message">The message.</param> |
| 42 | + /// <param name="exception">The exception.</param> |
| 43 | + public void Debug(object message, Exception exception) |
| 44 | + { |
| 45 | + log.DebugException(message.ToString(), exception); |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Logs a Debug format message. |
| 50 | + /// </summary> |
| 51 | + /// <param name="format">The format.</param> |
| 52 | + /// <param name="args">The args.</param> |
| 53 | + public void DebugFormat(string format, params object[] args) |
| 54 | + { |
| 55 | + log.Debug(format, args); |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Logs a Error message. |
| 60 | + /// </summary> |
| 61 | + /// <param name="message">The message.</param> |
| 62 | + public void Error(object message) |
| 63 | + { |
| 64 | + log.Error(message); |
| 65 | + } |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// Logs a Error message and exception. |
| 69 | + /// </summary> |
| 70 | + /// <param name="message">The message.</param> |
| 71 | + /// <param name="exception">The exception.</param> |
| 72 | + public void Error(object message, Exception exception) |
| 73 | + { |
| 74 | + log.ErrorException(message.ToString(), exception); |
| 75 | + } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Logs a Error format message. |
| 79 | + /// </summary> |
| 80 | + /// <param name="format">The format.</param> |
| 81 | + /// <param name="args">The args.</param> |
| 82 | + public void ErrorFormat(string format, params object[] args) |
| 83 | + { |
| 84 | + log.Error(format, args); |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Logs a Fatal message. |
| 89 | + /// </summary> |
| 90 | + /// <param name="message">The message.</param> |
| 91 | + public void Fatal(object message) |
| 92 | + { |
| 93 | + log.Fatal(message); |
| 94 | + } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Logs a Fatal message and exception. |
| 98 | + /// </summary> |
| 99 | + /// <param name="message">The message.</param> |
| 100 | + /// <param name="exception">The exception.</param> |
| 101 | + public void Fatal(object message, Exception exception) |
| 102 | + { |
| 103 | + log.FatalException(message.ToString(), exception); |
| 104 | + } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Logs a Error format message. |
| 108 | + /// </summary> |
| 109 | + /// <param name="format">The format.</param> |
| 110 | + /// <param name="args">The args.</param> |
| 111 | + public void FatalFormat(string format, params object[] args) |
| 112 | + { |
| 113 | + log.Fatal(format, args); |
| 114 | + } |
| 115 | + |
| 116 | + /// <summary> |
| 117 | + /// Logs an Info message and exception. |
| 118 | + /// </summary> |
| 119 | + /// <param name="message">The message.</param> |
| 120 | + public void Info(object message) |
| 121 | + { |
| 122 | + log.Info(message); |
| 123 | + } |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// Logs an Info message and exception. |
| 127 | + /// </summary> |
| 128 | + /// <param name="message">The message.</param> |
| 129 | + /// <param name="exception">The exception.</param> |
| 130 | + public void Info(object message, Exception exception) |
| 131 | + { |
| 132 | + log.InfoException(message.ToString(), exception); |
| 133 | + } |
| 134 | + |
| 135 | + /// <summary> |
| 136 | + /// Logs an Info format message. |
| 137 | + /// </summary> |
| 138 | + /// <param name="format">The format.</param> |
| 139 | + /// <param name="args">The args.</param> |
| 140 | + public void InfoFormat(string format, params object[] args) |
| 141 | + { |
| 142 | + log.Info(format, args); |
| 143 | + } |
| 144 | + |
| 145 | + /// <summary> |
| 146 | + /// Logs a Warning message. |
| 147 | + /// </summary> |
| 148 | + /// <param name="message">The message.</param> |
| 149 | + public void Warn(object message) |
| 150 | + { |
| 151 | + log.Warn(message); |
| 152 | + } |
| 153 | + |
| 154 | + /// <summary> |
| 155 | + /// Logs a Warning message and exception. |
| 156 | + /// </summary> |
| 157 | + /// <param name="message">The message.</param> |
| 158 | + /// <param name="exception">The exception.</param> |
| 159 | + public void Warn(object message, Exception exception) |
| 160 | + { |
| 161 | + log.WarnException(message.ToString(), exception); |
| 162 | + } |
| 163 | + |
| 164 | + /// <summary> |
| 165 | + /// Logs a Warning format message. |
| 166 | + /// </summary> |
| 167 | + /// <param name="format">The format.</param> |
| 168 | + /// <param name="args">The args.</param> |
| 169 | + public void WarnFormat(string format, params object[] args) |
| 170 | + { |
| 171 | + log.Warn(format, args); |
| 172 | + } |
| 173 | + } |
| 174 | +} |
0 commit comments