Ignore:
Timestamp:
02/09/10 07:23:22 (5 years ago)
Author:
lowjoel
Message:

Redesigned the Logger paradigm -- instead of a dealing with a logger object to do any form of logging, we have a static Logger class which code can log to, and define log targets to receive those logs. Also included is a LogSession? class which sets the log target for the current thread or for a few threads. Addresses #320: Logging improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.DefaultPlugins/FileSystems/Windows.cs

    r1745 r1777  
    155155 
    156156        public override void EraseClusterTips(VolumeInfo info, ErasureMethod method, 
    157             Logger log, ClusterTipsSearchProgress searchCallback, 
    158             ClusterTipsEraseProgress eraseCallback) 
     157            ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback) 
    159158        { 
    160159            //List all the files which can be erased. 
     
    163162                throw new InvalidOperationException(S._("Could not erase cluster tips in {0} " + 
    164163                    "as the volume is not mounted.", info.VolumeId)); 
    165             ListFiles(new DirectoryInfo(info.MountPoints[0]), files, log, searchCallback); 
     164            ListFiles(new DirectoryInfo(info.MountPoints[0]), files, searchCallback); 
    166165 
    167166            //For every file, erase the cluster tips. 
     
    180179                catch (UnauthorizedAccessException) 
    181180                { 
    182                     log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 
    183                         "cluster tips erased because you do not have the required permissions to " + 
    184                         "erase the file cluster tips.", files[i]), LogLevel.Information)); 
     181                    Logger.Log(S._("{0} did not have its cluster tips erased because you do not " + 
     182                        "have the required permissions to erase the file cluster tips.", files[i]), 
     183                        LogLevel.Information); 
    185184                } 
    186185                catch (IOException e) 
    187186                { 
    188                     log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 
    189                         "cluster tips erased. The error returned was: {1}", files[i], 
    190                         e.Message), LogLevel.Error)); 
     187                    Logger.Log(S._("{0} did not have its cluster tips erased. The error returned " + 
     188                        "was: {1}", files[i], e.Message), LogLevel.Error); 
    191189                } 
    192190                finally 
     
    194192                    streamInfo.Attributes = fileAttr; 
    195193                } 
     194 
    196195                eraseCallback(i, files.Count, files[i]); 
    197196            } 
    198197        } 
    199198 
    200         private void ListFiles(DirectoryInfo info, List<string> files, Logger log, 
     199        private void ListFiles(DirectoryInfo info, List<string> files, 
    201200            ClusterTipsSearchProgress searchCallback) 
    202201        { 
     
    206205                if ((info.Attributes & FileAttributes.ReparsePoint) != 0) 
    207206                { 
    208                     log.LastSessionEntries.Add(new LogEntry(S._("Files in {0} did " + 
    209                         "not have their cluster tips erased because it is a hard link or " + 
    210                         "a symbolic link.", info.FullName), LogLevel.Information)); 
     207                    Logger.Log(S._("Files in {0} did not have their cluster tips erased because " + 
     208                        "it is a hard link or a symbolic link.", info.FullName), 
     209                        LogLevel.Information); 
    211210                    return; 
    212211                } 
     
    214213                foreach (FileInfo file in info.GetFiles()) 
    215214                    if (file.IsProtectedSystemFile()) 
    216                         log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 
    217                             "its cluster tips erased, because it is a system file", 
    218                             file.FullName), LogLevel.Information)); 
     215                        Logger.Log(S._("{0} did not have its cluster tips erased, because it is " + 
     216                            "a system file", file.FullName), LogLevel.Information); 
    219217                    else if ((file.Attributes & FileAttributes.ReparsePoint) != 0) 
    220                         log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 
    221                             "its cluster tips erased because it is a hard link or a " + 
    222                             "symbolic link.", file.FullName), LogLevel.Information)); 
     218                        Logger.Log(S._("{0} did not have its cluster tips erased because it is a " + 
     219                            "hard link or a symbolic link.", file.FullName), LogLevel.Information); 
    223220                    else if ((file.Attributes & FileAttributes.Compressed) != 0 || 
    224221                        (file.Attributes & FileAttributes.Encrypted) != 0 || 
    225222                        (file.Attributes & FileAttributes.SparseFile) != 0) 
    226223                    { 
    227                         log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 
    228                             "its cluster tips erased because it is compressed, encrypted " + 
    229                             "or a sparse file.", file.FullName), LogLevel.Information)); 
     224                        Logger.Log(S._("{0} did not have its cluster tips erased because it is " + 
     225                            "compressed, encrypted or a sparse file.", file.FullName), 
     226                            LogLevel.Information); 
    230227                    } 
    231228                    else 
     
    240237                        catch (UnauthorizedAccessException e) 
    241238                        { 
    242                             log.LastSessionEntries.Add(new LogEntry(S._("{0} did not " + 
    243                                 "have its cluster tips erased because of the following " + 
    244                                 "error: {1}", info.FullName, e.Message), LogLevel.Error)); 
     239                            Logger.Log(S._("{0} did not have its cluster tips erased because of " + 
     240                                "the following error: {1}", info.FullName, e.Message), 
     241                                LogLevel.Error); 
    245242                        } 
    246243                        catch (IOException e) 
    247244                        { 
    248                             log.LastSessionEntries.Add(new LogEntry(S._("{0} did not " + 
    249                                 "have its cluster tips erased because of the following " + 
    250                                 "error: {1}", info.FullName, e.Message), LogLevel.Error)); 
     245                            Logger.Log(S._("{0} did not have its cluster tips erased because of " + 
     246                                "the following error: {1}", info.FullName, e.Message), 
     247                                LogLevel.Error); 
    251248                        } 
    252249                    } 
     
    255252                { 
    256253                    searchCallback(subDirInfo.FullName); 
    257                     ListFiles(subDirInfo, files, log, searchCallback); 
     254                    ListFiles(subDirInfo, files, searchCallback); 
    258255                } 
    259256            } 
    260257            catch (UnauthorizedAccessException e) 
    261258            { 
    262                 log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 
    263                     "cluster tips erased because of the following error: {1}", 
    264                     info.FullName, e.Message), LogLevel.Error)); 
     259                Logger.Log(S._("{0} did not have its cluster tips erased because of the " + 
     260                    "following error: {1}", info.FullName, e.Message), LogLevel.Error); 
    265261            } 
    266262            catch (IOException e) 
    267263            { 
    268                 log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 
    269                     "cluster tips erased because of the following error: {1}", 
    270                     info.FullName, e.Message), LogLevel.Error)); 
     264                Logger.Log(S._("{0} did not have its cluster tips erased because of the " + 
     265                    "following error: {1}", info.FullName, e.Message), LogLevel.Error); 
    271266            } 
    272267        } 
Note: See TracChangeset for help on using the changeset viewer.