void FakeProcessingMethod() { try { String caller = this.GetFormattedCallerInfoString(); LogExt.Info(caller, "Starting Processing."); LogExt.Debug(caller, "Calling Network."); String data = FakeDataGetter(); LogExt.Debug(caller, data); LogExt.Info(caller, "Finishing Processing."); } catch (Exception ex) { throw new InvalidOperationException("Failed get data because of I/O problem.", ex); } }
public void Run() { String log4netConfigString = @" <log4net> <root> <level value=""DEBUG"" /> <appender-ref ref=""ColoredConsoleAppender"" /> </root> <appender name=""ColoredConsoleAppender"" type=""log4net.Appender.ColoredConsoleAppender""> <mapping> <level value=""INFO"" /> <forecolor value=""White"" /> </mapping> <mapping> <level value=""WARN"" /> <forecolor value=""Yellow"" /> </mapping> <mapping> <level value=""ERROR"" /> <forecolor value=""Red"" /> </mapping> <mapping> <level value=""FATAL"" /> <forecolor value=""White"" /> <backColor value=""Red, HighIntensity"" /> </mapping> <mapping> <level value=""DEBUG"" /> <forecolor value=""Green"" /> </mapping> <layout type=""log4net.Layout.PatternLayout""> <conversionPattern value=""%-4t %d{ABSOLUTE} %-5p [%c] %m%n"" /> </layout> </appender> </log4net> "; using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(log4netConfigString); writer.Flush(); stream.Position = 0; XmlConfigurator.Configure(stream); } } String caller = this.GetFormattedCallerInfoString(); LogExt.Info(caller, "Doing log."); LogExt.Debug(caller, "Log4Net config:"); LogExt.Debug(caller, log4netConfigString); try { LogExt.Info(caller, "Read the network."); NetworkReader(); LogExt.Info(caller, "Read the network done."); } catch (Exception ex) { LogExt.Error(caller, ex); } try { LogExt.Info(caller, "Process the data."); FakeProcessingMethod(); LogExt.Info(caller, "Process the data done."); } catch (Exception ex) { LogExt.Error(caller, ex); } LogExt.Info(caller, "Doing log done."); }