Annotation of /trunk/AssetServer/Logger.cs
Parent Directory
|
Revision Log
Revision 76 - (view) (download)
| 1 : | jhurliman | 48 | /* |
| 2 : | * Copyright (c) 2008 Intel Corporation | ||
| 3 : | * All rights reserved. | ||
| 4 : | * Redistribution and use in source and binary forms, with or without | ||
| 5 : | * modification, are permitted provided that the following conditions | ||
| 6 : | * are met: | ||
| 7 : | * | ||
| 8 : | * -- Redistributions of source code must retain the above copyright | ||
| 9 : | * notice, this list of conditions and the following disclaimer. | ||
| 10 : | * -- Redistributions in binary form must reproduce the above copyright | ||
| 11 : | * notice, this list of conditions and the following disclaimer in the | ||
| 12 : | * documentation and/or other materials provided with the distribution. | ||
| 13 : | * -- Neither the name of the Intel Corporation nor the names of its | ||
| 14 : | * contributors may be used to endorse or promote products derived from | ||
| 15 : | * this software without specific prior written permission. | ||
| 16 : | * | ||
| 17 : | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 18 : | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 19 : | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
| 20 : | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS | ||
| 21 : | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 : | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 : | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 24 : | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 25 : | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 26 : | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 27 : | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 : | */ | ||
| 29 : | |||
| 30 : | using System; | ||
| 31 : | jhurliman | 76 | using HttpServer; |
| 32 : | jhurliman | 48 | using log4net; |
| 33 : | using log4net.Config; | ||
| 34 : | |||
| 35 : | jhurliman | 57 | [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net")] |
| 36 : | jhurliman | 48 | |
| 37 : | namespace AssetServer | ||
| 38 : | { | ||
| 39 : | /// <summary> | ||
| 40 : | /// Singleton logging class for the entire library | ||
| 41 : | /// </summary> | ||
| 42 : | public static class Logger | ||
| 43 : | { | ||
| 44 : | /// <summary>log4net logging engine</summary> | ||
| 45 : | public static ILog Log; | ||
| 46 : | |||
| 47 : | static Logger() | ||
| 48 : | { | ||
| 49 : | jhurliman | 57 | Log = LogManager.GetLogger(System.Reflection.Assembly.GetExecutingAssembly().FullName); |
| 50 : | jhurliman | 48 | |
| 51 : | // If error level reporting isn't enabled we assume no logger is configured and initialize a default | ||
| 52 : | // ConsoleAppender | ||
| 53 : | if (!Log.Logger.IsEnabledFor(log4net.Core.Level.Error)) | ||
| 54 : | { | ||
| 55 : | log4net.Appender.ConsoleAppender appender = new log4net.Appender.ConsoleAppender(); | ||
| 56 : | appender.Layout = new log4net.Layout.PatternLayout("%timestamp [%thread] %-5level - %message%newline"); | ||
| 57 : | BasicConfigurator.Configure(appender); | ||
| 58 : | |||
| 59 : | Log.Info("No log configuration found, defaulting to console logging"); | ||
| 60 : | } | ||
| 61 : | } | ||
| 62 : | } | ||
| 63 : | jhurliman | 76 | |
| 64 : | public class log4netLogWriter : ILogWriter | ||
| 65 : | { | ||
| 66 : | /// <summary> | ||
| 67 : | /// Singleton instance of this class | ||
| 68 : | /// </summary> | ||
| 69 : | public static log4netLogWriter Instance = new log4netLogWriter(Logger.Log); | ||
| 70 : | |||
| 71 : | ILog Log; | ||
| 72 : | |||
| 73 : | log4netLogWriter(ILog log) | ||
| 74 : | { | ||
| 75 : | Log = log; | ||
| 76 : | } | ||
| 77 : | |||
| 78 : | public void Write(object source, LogPrio prio, string message) | ||
| 79 : | { | ||
| 80 : | switch (prio) | ||
| 81 : | { | ||
| 82 : | case LogPrio.Trace: | ||
| 83 : | case LogPrio.Debug: | ||
| 84 : | Log.DebugFormat("{0}: {1}", source, message); | ||
| 85 : | break; | ||
| 86 : | case LogPrio.Info: | ||
| 87 : | Log.InfoFormat("{0}: {1}", source, message); | ||
| 88 : | break; | ||
| 89 : | case LogPrio.Warning: | ||
| 90 : | Log.WarnFormat("{0}: {1}", source, message); | ||
| 91 : | break; | ||
| 92 : | case LogPrio.Error: | ||
| 93 : | Log.ErrorFormat("{0}: {1}", source, message); | ||
| 94 : | break; | ||
| 95 : | case LogPrio.Fatal: | ||
| 96 : | Log.FatalFormat("{0}: {1}", source, message); | ||
| 97 : | break; | ||
| 98 : | } | ||
| 99 : | } | ||
| 100 : | } | ||
| 101 : | jhurliman | 48 | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

