Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/11 12:24:33 (14 years ago)
Author:
ascheibe
Message:

#1517

  • rewrote Logger to use Diagnostics.Trace
  • removed HiveLogger as it's not used anymore
  • removed dependency from Persistence to log4net
  • ConfigMerger now also merges <system.diagnostics> sections
Location:
trunk/sources/HeuristicLab.Tracing/3.3
Files:
3 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tracing/3.3/HeuristicLab.Tracing-3.3.csproj

    r5163 r6173  
    9696  </PropertyGroup>
    9797  <ItemGroup>
    98     <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
    99       <SpecificVersion>False</SpecificVersion>
    100       <HintPath>..\..\HeuristicLab.ExtLibs\HeuristicLab.log4net\1.2.10.0\log4net.dll</HintPath>
    101     </Reference>
    10298    <Reference Include="System" />
    10399    <Reference Include="System.Core">
     
    115111  <ItemGroup>
    116112    <None Include="HeuristicLabTracingPlugin.cs.frame" />
    117     <Compile Include="HiveLogger.cs" />
     113    <Compile Include="HeuristicLabTracingPlugin.cs" />
    118114    <Compile Include="Logger.cs" />
    119     <Compile Include="HeuristicLabTracingPlugin.cs" />
    120115    <Compile Include="Properties\AssemblyInfo.cs" />
    121116    <Compile Include="Properties\Settings.Designer.cs">
     
    126121  </ItemGroup>
    127122  <ItemGroup>
    128     <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.log4net\1.2.10.0\HeuristicLab.log4net-1.2.10.0.csproj">
    129       <Project>{1B3063DB-D71C-4A6A-A359-883E8F53A140}</Project>
    130       <Name>HeuristicLab.log4net-1.2.10.0</Name>
    131     </ProjectReference>
    132123    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    133124      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
     
    143134      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    144135    </None>
    145     <Content Include="HeuristicLab.log4net.xml">
    146       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    147     </Content>
    148   </ItemGroup>
    149   <ItemGroup>
    150     <Content Include="HeuristicLab.Hive.log4net.xml">
    151       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    152     </Content>
    153136  </ItemGroup>
    154137  <ItemGroup>
  • trunk/sources/HeuristicLab.Tracing/3.3/HeuristicLabTracingPlugin.cs.frame

    r6099 r6173  
    2929  [Plugin("HeuristicLab.Tracing", "3.3.4.$WCREV$")]
    3030  [PluginFile("HeuristicLab.Tracing-3.3.dll", PluginFileType.Assembly)]
    31   [PluginFile("HeuristicLab.log4net.xml", PluginFileType.Data)]
    32   [PluginDependency("HeuristicLab.log4net", "1.2.10.0")]
    3331  public class HeuristicLabPersistencePlugin : PluginBase {}
    3432
  • trunk/sources/HeuristicLab.Tracing/3.3/Logger.cs

    r5445 r6173  
    2020#endregion
    2121
     22
    2223using System;
    2324using System.Diagnostics;
    24 using System.IO;
    25 using HeuristicLab.Tracing.Properties;
    26 using log4net;
    27 using log4net.Config;
    28 
    2925namespace HeuristicLab.Tracing {
    3026
    3127  /// <summary>
    32   /// HeuristicLab Tracing entry point. Default logger. Reads configured tracing
    33   /// file and provides automatic logging with reflection of the calling type.
     28  /// HeuristicLab.Tracing using System.Diagnostics.Trace.
     29  /// Note that tracing is only activated if the DEBUG or TRACE symbol is set.
     30  /// Configuration (type of listener, file name, ...) is done in app.config in the <system.diagnostics> section.
    3431  /// </summary>
    3532  public class Logger {
    3633
    3734    /// <summary>
    38     /// true if Configure has been called already.
     35    /// Issues a debug message.
    3936    /// </summary>
    40     protected static bool IsConfigured = false;
    41 
    42     /// <summary>
    43     /// Configures this instance: Reads the log file specified in the settings.
    44     /// </summary>
    45     protected static void Configure() {
    46       if (IsConfigured) return;
    47       IsConfigured = true;
    48       if (string.IsNullOrEmpty(Settings.Default.TracingLog4netConfigFile)) {
    49         Settings.Default.TracingLog4netConfigFile =
    50             "HeuristicLab.log4net.xml";
    51       }
    52       XmlConfigurator.ConfigureAndWatch(
    53         new FileInfo(Settings.Default.TracingLog4netConfigFile));
    54       Info("logging initialized " + DateTime.Now);
     37    /// <param name="message">The message.</param>
     38    public static void Debug(object message) {
     39      StackFrame frame = new StackFrame(1);
     40      Trace.TraceInformation(frame.GetMethod().DeclaringType.ToString() + " - " + message.ToString());
    5541    }
    5642
    5743    /// <summary>
    58     /// Gets the default logger for the calling class n levels up in the
    59     /// call hierarchy.
     44    /// Issues an informational message.
    6045    /// </summary>
    61     /// <param name="nParents">The number of parent calls.</param>
    62     /// <returns>An <see cref="ILog"/> instance.</returns>
    63     public static ILog GetDefaultLogger(int nParents) {
    64       Configure();
    65       StackFrame frame = new StackFrame(nParents + 1);
    66       return LogManager.GetLogger(frame.GetMethod().DeclaringType);
     46    /// <param name="message">The message.</param>
     47    public static void Info(object message) {
     48      StackFrame frame = new StackFrame(1);
     49      Trace.TraceInformation(frame.GetMethod().DeclaringType.ToString() + " - " + message.ToString());
    6750    }
    6851
    6952    /// <summary>
    70     /// Gets the default logger: The logger for the class of the
    71     /// calling method.
     53    /// Issues a warning message.
    7254    /// </summary>
    73     /// <returns>An <see cref="ILog"/> instance.</returns>
    74     public static ILog GetDefaultLogger() {
    75       Configure();
     55    /// <param name="message">The message.</param>
     56    public static void Warn(object message) {
    7657      StackFrame frame = new StackFrame(1);
    77       return LogManager.GetLogger(frame.GetMethod().DeclaringType);
     58      Trace.TraceWarning(frame.GetMethod().DeclaringType.ToString() + " - " + message.ToString());
    7859    }
    7960
    8061    /// <summary>
    81     /// Issues a debug message to the default logger.
     62    /// Issues an error message.
    8263    /// </summary>
    8364    /// <param name="message">The message.</param>
    84     public static void Debug(object message) {
    85       GetDefaultLogger(1).Debug(message);
     65    public static void Error(object message) {
     66      StackFrame frame = new StackFrame(1);
     67      Trace.TraceError(frame.GetMethod().DeclaringType.ToString() + " - " + message.ToString());
    8668    }
    8769
    8870    /// <summary>
    89     /// Issues an informational message to the default logger.
    90     /// </summary>
    91     /// <param name="message">The message.</param>
    92     public static void Info(object message) {
    93       GetDefaultLogger(1).Info(message);
    94     }
    95 
    96     /// <summary>
    97     /// Issues a warning message to the default logger.
    98     /// </summary>
    99     /// <param name="message">The message.</param>
    100     public static void Warn(object message) {
    101       GetDefaultLogger(1).Warn(message);
    102     }
    103 
    104     /// <summary>
    105     /// Issues an error message to the default logger.
    106     /// </summary>
    107     /// <param name="message">The message.</param>
    108     public static void Error(object message) {
    109       GetDefaultLogger(1).Error(message);
    110     }
    111 
    112     /// <summary>
    113     /// Issues a fatal error message to the default logger.
    114     /// </summary>
    115     /// <param name="message">The message.</param>
    116     public static void Fatal(object message) {
    117       GetDefaultLogger(1).Fatal(message);
    118     }
    119 
    120     /// <summary>
    121     /// Issues a debug message to the logger of the specified type.
     71    /// Issues a debug message of the specified type.
    12272    /// </summary>
    12373    /// <param name="type">The type.</param>
    12474    /// <param name="message">The message.</param>
    12575    public static void Debug(Type type, object message) {
    126       Configure();
    127       LogManager.GetLogger(type).Debug(message);
     76      Trace.TraceInformation(type.ToString() + ": " + message.ToString());
    12877    }
    12978
    13079    /// <summary>
    131     /// Issues an iformational message to the logger of the specified
    132     /// type.
     80    /// Issues an informational message of the specified type.
    13381    /// </summary>
    13482    /// <param name="type">The type.</param>
    13583    /// <param name="message">The message.</param>
    13684    public static void Info(Type type, object message) {
    137       Configure();
    138       LogManager.GetLogger(type).Info(message);
     85      Trace.TraceInformation(type.ToString() + ": " + message.ToString());
    13986    }
    14087
    14188    /// <summary>
    142     /// Issues a warning message to the logger of
    143     /// the specified type.
     89    /// Issues a warning message of the specified type.
    14490    /// </summary>
    14591    /// <param name="type">The type.</param>
    14692    /// <param name="message">The message.</param>
    14793    public static void Warn(Type type, object message) {
    148       Configure();
    149       LogManager.GetLogger(type).Warn(message);
     94      Trace.TraceWarning(type.ToString() + ": " + message.ToString());
    15095    }
    15196
    15297    /// <summary>
    153     /// Issues an error message to the logger of the specified
    154     /// type.
     98    /// Issues an error message of the specified type.
    15599    /// </summary>
    156100    /// <param name="type">The type.</param>
    157101    /// <param name="message">The message.</param>
    158102    public static void Error(Type type, object message) {
    159       Configure();
    160       LogManager.GetLogger(type).Error(message);
     103      Trace.TraceError(type.ToString() + ": " + message.ToString());
    161104    }
    162105
    163106    /// <summary>
    164     /// Issues a fatal error message to the logger of
    165     /// the specified type.
    166     /// </summary>
    167     /// <param name="type">The type.</param>
    168     /// <param name="message">The message.</param>
    169     public static void Fatal(Type type, object message) {
    170       Configure();
    171       LogManager.GetLogger(type).Fatal(message);
    172     }
    173 
    174     /// <summary>
    175     /// Issues a debug message to the default
    176     /// logger including an exception.
     107    /// Issues a debug message including an exception.
    177108    /// </summary>
    178109    /// <param name="message">The message.</param>
    179110    /// <param name="exception">The exception.</param>
    180111    public static void Debug(object message, Exception exception) {
    181       GetDefaultLogger(1).Debug(message, exception);
     112      Trace.TraceInformation(message.ToString() + ": " + exception.ToString());
    182113    }
    183114
    184115    /// <summary>
    185     /// Issues an informational message to the default
    186     /// logger including an exception.
     116    /// Issues an informational message including an exception.
    187117    /// </summary>
    188118    /// <param name="message">The message.</param>
    189     /// <param name="exception">The exception.</param>
    190 
     119    /// <param name="exception">The exception.</param>       
    191120    public static void Info(object message, Exception exception) {
    192       GetDefaultLogger(1).Info(message, exception);
     121      Trace.TraceInformation(message.ToString() + ": " + exception.ToString());
    193122    }
    194123
    195124    /// <summary>
    196     /// Issues a warning message to the default
    197     /// logger including an exception.
     125    /// Issues a warning message including an exception.
    198126    /// </summary>
    199127    /// <param name="message">The message.</param>
    200128    /// <param name="exception">The exception.</param>
    201129    public static void Warn(object message, Exception exception) {
    202       GetDefaultLogger(1).Warn(message, exception);
     130      Trace.TraceWarning(message.ToString() + ": " + exception.ToString());
    203131    }
    204132
    205133    /// <summary>
    206     /// Issues an error message to the default
    207     /// logger including an exception.
     134    /// Issues an error message including an exception.
    208135    /// </summary>
    209136    /// <param name="message">The message.</param>
    210137    /// <param name="exception">The exception.</param>
    211138    public static void Error(object message, Exception exception) {
    212       GetDefaultLogger(1).Error(message, exception);
     139      Trace.TraceError(message.ToString() + ": " + exception.ToString());
    213140    }
    214141
    215142    /// <summary>
    216     /// Issues a fatal error message to the default
    217     /// logger including an exception.
    218     /// </summary>
    219     /// <param name="message">The message.</param>
    220     /// <param name="exception">The exception.</param>
    221     public static void Fatal(object message, Exception exception) {
    222       GetDefaultLogger(1).Fatal(message, exception);
    223     }
    224 
    225     /// <summary>
    226     /// Issues a debug message to the logger of the specified
    227     /// type including an exception.
     143    /// Issues a debug message of the specified type including an exception.
    228144    /// </summary>
    229145    /// <param name="type">The type.</param>
     
    231147    /// <param name="exception">The exception.</param>
    232148    public static void Debug(Type type, object message, Exception exception) {
    233       Configure();
    234       LogManager.GetLogger(type).Debug(message, exception);
     149      Trace.TraceInformation(type.ToString() + ": " + message.ToString() + ": " + exception.ToString());
    235150    }
    236151
    237152    /// <summary>
    238     /// Issues an informational message to the logger of the specified
    239     /// type including an exception.
     153    /// Issues an informational message of the specified type including an exception.
    240154    /// </summary>
    241155    /// <param name="type">The type.</param>
     
    243157    /// <param name="exception">The exception.</param>
    244158    public static void Info(Type type, object message, Exception exception) {
    245       Configure();
    246       LogManager.GetLogger(type).Info(message, exception);
     159      Trace.TraceInformation(type.ToString() + ": " + message.ToString() + ": " + exception.ToString());
    247160    }
    248161
    249162    /// <summary>
    250     /// Issues a warning message to the logger of the specified
    251     /// type including an exception.
     163    /// Issues a warning message of the specified type including an exception.
    252164    /// </summary>
    253165    /// <param name="type">The type.</param>
     
    255167    /// <param name="exception">The exception.</param>
    256168    public static void Warn(Type type, object message, Exception exception) {
    257       Configure();
    258       LogManager.GetLogger(type).Warn(message, exception);
     169      Trace.TraceWarning(type.ToString() + ": " + message.ToString() + ": " + exception.ToString());
    259170    }
    260171
    261172    /// <summary>
    262     /// Issues an error message to the logger of the specified
    263     /// type including an exception.
     173    /// Issues an error message of the specified type including an exception.
    264174    /// </summary>
    265175    /// <param name="type">The type.</param>
     
    267177    /// <param name="exception">The exception.</param>
    268178    public static void Error(Type type, object message, Exception exception) {
    269       Configure();
    270       LogManager.GetLogger(type).Error(message, exception);
    271     }
    272 
    273     /// <summary>
    274     /// Issues a fatal error message to the logger of the specified
    275     /// type including an exception.
    276     /// </summary>
    277     /// <param name="type">The type.</param>
    278     /// <param name="message">The message.</param>
    279     /// <param name="exception">The exception.</param>
    280     public static void Fatal(Type type, object message, Exception exception) {
    281       Configure();
    282       LogManager.GetLogger(type).Fatal(message, exception);
     179      Trace.TraceError(type.ToString() + ": " + message.ToString() + ": " + exception.ToString());
    283180    }
    284181  }
  • trunk/sources/HeuristicLab.Tracing/3.3/Properties/Settings.Designer.cs

    r4065 r6173  
    22// <auto-generated>
    33//     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.1
     4//     Runtime Version:4.0.30319.225
    55//
    66//     Changes to this file may cause incorrect behavior and will be lost if
     
    2323            }
    2424        }
    25        
    26         [global::System.Configuration.UserScopedSettingAttribute()]
    27         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    28         [global::System.Configuration.DefaultSettingValueAttribute("")]
    29         public string TracingLog4netConfigFile {
    30             get {
    31                 return ((string)(this["TracingLog4netConfigFile"]));
    32             }
    33             set {
    34                 this["TracingLog4netConfigFile"] = value;
    35             }
    36         }
    3725    }
    3826}
  • trunk/sources/HeuristicLab.Tracing/3.3/Properties/Settings.settings

    r1622 r6173  
    33  <Profiles />
    44  <Settings>
    5     <Setting Name="TracingLog4netConfigFile" Type="System.String" Scope="User">
    6       <Value Profile="(Default)" />
    7     </Setting>
     5   
    86  </Settings>
    97</SettingsFile>
  • trunk/sources/HeuristicLab.Tracing/3.3/app.config

    r5163 r6173  
    11<?xml version="1.0"?>
    2 <configuration>
     2<configuration>       
     3  <system.diagnostics>
     4    <trace autoflush="true" indentsize="4">
     5      <listeners>
     6        <add name="HeuristicLabListener"
     7          type="System.Diagnostics.TextWriterTraceListener"
     8          initializeData="HeuristicLab.log" />
     9        <remove name="Default" />
     10      </listeners>
     11    </trace>
     12  </system.diagnostics>
    313  <configSections>   
    414    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     
    818  <userSettings>
    919    <HeuristicLab.Tracing.Properties.Settings>
    10       <setting name="TracingLog4netConfigFile" serializeAs="String">
    11         <value/>
    12       </setting>
     20   
    1321    </HeuristicLab.Tracing.Properties.Settings>
    1422  </userSettings>
Note: See TracChangeset for help on using the changeset viewer.