Click here to Skip to main content
15,884,353 members
Articles / Database Development / SQL Server / SQL Server 2008

Continuous Integration for Databases with Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.85/5 (14 votes)
23 Nov 2010Apache18 min read 63K   1.2K   68  
Provides a framework for predictably compiling, extracting, and deploying a database project.
// <copyright file="BaseLog.cs" company="Adam Nachman">
// Copyright (c) 2009 All Right Reserved Adam Nachman
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Adam Nachman</author>
namespace SqlDeployment.Build
{
    using System;
    using Microsoft.Build.Utilities;

    /// <summary>
    /// A default logger
    /// </summary>
    internal class BaseLog : SqlDeployment.Interfaces.ILogger
    {
        #region Private Static Variables

        /// <summary>
        /// The static ILogger class
        /// </summary>
        private static SqlDeployment.Interfaces.ILogger logger;

        #endregion Private Static Variables

        /// <summary>
        /// Initializes a new instance of the BaseLog class
        /// </summary>
        public BaseLog()
            : this(new TraceLog())
        {
        }

        /// <summary>
        /// Initializes a new instance of the BaseLog class
        /// </summary>
        /// <param name="buildLogger">The logger object to use</param>
        public BaseLog(object buildLogger)
        {
            logger = (SqlDeployment.Interfaces.ILogger)buildLogger;
        }

        #region Public Methods

        /// <summary>
        /// Initializes the logger
        /// </summary>
        /// <param name="buildTask">The task object with which to iitialize the looger</param>
        public void Init(object buildTask)
        {
            if (buildTask is Task)
            {
                Task task = (Task)buildTask;
                if (task.BuildEngine == null)
                {
                    logger = new TraceLog();
                }
                else
                {
                    logger = new BuildLog();
                    logger.Init(task.Log);
                }
            }
            else
            {
                logger = new TraceLog();
            }
        }

        /// <summary>
        /// Logs an information message
        /// </summary>
        /// <param name="message">The message text</param>
        public void LogInformation(string message)
        {
            logger.LogInformation(message);
        }

        /// <summary>
        /// Logs an information message
        /// </summary>
        /// <param name="format">The format of the message</param>
        /// <param name="args">The arguments</param>
        public void LogInformation(string format, params object[] args)
        {
            logger.LogInformation(String.Format(format, args));
        }

        /// <summary>
        /// Logs a warning message
        /// </summary>
        /// <param name="message">The message text</param>
        public void LogWarning(string message)
        {
            logger.LogWarning(message);
        }

        /// <summary>
        /// Logs a warning message
        /// </summary>
        /// <param name="format">The format of the message</param>
        /// <param name="args">The arguments</param>
        public void LogWarning(string format, params object[] args)
        {
            logger.LogWarning(String.Format(format, args));
        }

        /// <summary>
        /// Logs an error
        /// </summary>
        /// <param name="message">The message text</param>
        public void LogError(string message)
        {
            logger.LogError(message);
        }

        /// <summary>
        /// Logs an error
        /// </summary>
        /// <param name="format">The format of the message</param>
        /// <param name="args">The arguments</param>
        public void LogError(string format, params object[] args)
        {
            logger.LogError(String.Format(format, args));
        }

        /// <summary>
        /// Logs an error from an exception
        /// </summary>
        /// <param name="ex">The exception</param>
        /// <returns>False if unsuccessful</returns>
        public bool LogErrorFromException(Exception ex)
        {
            return logger.LogErrorFromException(ex);
        }

        #endregion Public Methods
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Chief Technology Officer
Australia Australia
Emigrated to Sydney, Australia in 2013 from Cape Town, South Africa, and have been writing commercial software since 1997.

Expertise includes MS SQL Server (7 till latest), C#, VB6, VB.NET, VBScript, JavaScript, ASP, HTML, WPF Angular, Windows Installer and InstallShield (multiple versions) and a partridge in a pear tree. MSBuild, CruiseControl.NET, TFS, Jenkins, TeamCity, ant and nant are all necessary sidelines. Have tinkered with Java and C++

Experienced with Enterprise level application design and deployment, as well as sizing and scaling high volume OLTP database designs up to tens of thousands of transactions per second and diagnosing application and database performance bottlenecks.

Comments and Discussions