Folder to Zip - code Maintainability From the code metrics in VS it says that the maintainability index is 64.
I think the code is really easy written.

How can I get a higher Maintainability Index?

public void ExportProjectFolderToZip()
{
    Log4NetLogger.Logger.Info("Start of Method ExportProjectFolderToZip");
    var startPath = new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).LocalPath; //get current directory (Release/Debug)
    var zipPath = new Uri(@"" + startPath + "-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".zip").LocalPath;  //zip filename
    try
    {
        CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true); //create zip folder
    }
    catch (Exception ex)
    {
        Log4NetLogger.Logger.Error("Error: " + ex.Message);
    }
    Log4NetLogger.Logger.Info("End of Method ExportProjectFolderToZip");
}
First a quote from Code Metrics Values on MSDN to make sure everyone knows what it is:


  Maintainability Index – Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability. Color coded ratings can be used to quickly identify trouble spots in your code. A green rating is between 20 and 100 and indicates that the code has good maintainability. A yellow rating is between 10 and 19 and indicates that the code is moderately maintainable. A red rating is a rating between 0 and 9 and indicates low maintainability.


So is your code maintainable? Well, even though the score is not so bad I don't think it's. Why? Because it does two things that it shouldn't which are:


var startPath = new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).LocalPath; //get current directory (Release/Debug)
var zipPath = new Uri(@"" + startPath + "-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".zip").LocalPath;  //zip filename



You can see this by looking at another even more important score the


  Class Coupling – Measures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types.


I measured your code and this score is 8. There is a way to improved it if you encapsulate the code creating the paths. Currently those two lines cannot be tested so you actually have to debug or run your application to be able to verify that both paths are the ones you expect.

If you put them inside another tool like a PathBuilder

class PathBuilder : IPathBuilder
{
    public string CreateStartPath()
    {
        return new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).LocalPath;
    }

    public string CreateZipPath(string startPath)
    {
        return new Uri(@"" + startPath + "-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".zip").LocalPath;
    }
}


the class-coupling score drops to 3 and 2 for each of the PathBuilder methods which is much better now:

public static void ExportProjectFolderToZip(PathBuilder pathBuilder)
{
    try
    {
        var startPath = pathBuilder.CreateStartPath(); 
        var zipPath = pathBuilder.CreateZipPath(startPath);

        CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
    }
    catch (Exception ex)
    {
        Logger.Error("Error: " + ex.Message);
    }        
}


Btw this is not how you should use the logger for exceptions: Logger.Error("Error: " + ex.Message); There is an overload that accepts an exception so that you don't loose the stack-trace.