café com bug - 2ª edição em 13/05/2010

Post on 23-Jun-2015

666 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Slides da apresentação que fiz na segunda edição do nosso encontro, Café com Bug, no dia 13/05/2010 realizado na WeFit

TRANSCRIPT

rev. 2

com

Foco em

Escalabilidade

Tratamento de Exceções

Logging/Debugging

EscalabilidadeCapacidade Máxima: 100 usuários

100 usuários = 100%

150 novos usuários

Capacidade necessária: 250 usuários = 150%+!

#Comofas?

#Comofas2?

#Comofas3?

Load Balance

1 2 3 4 5 6

Tratamento de Exceções

Como tratar?

Avisar Informar Armazenar

A solução!

Global.asax

protected void Application_Error(object sender, EventArgs e){ Exception ex = Server.GetLastError(); RSLHandler handler = new RSLHandler().Configure(); handler.Handle(ex);}

E o usuário ve isso...

Quando deveria ver...

A solução!

Web.Config:

<customErrors defaultRedirect=“erroPadrao.html" mode="On"> <error statusCode=“403" redirect=“NaoPermitida.html"/><error statusCode=“404" redirect=“NaoEncontrada.html"/>

</customErrors>

Errado #1private void Salvar(Usuario novoUsuario){

//Abre conexão com banco de dadosDataReader dr = cmd.Execute(sql);//Executa uma instrução que gera exceptionthrow new Exception(“Whatever”);

}

Certo #1private void Salvar(Usuario novoUsuario){

DataReader dr = cmd.ExecuteReader(sql, CommandBehavior.CloseConnection);try {

//Executa uma instrução que gera exceptionthrow new Exception(“Whatever”);

}finally{dr.Close();

}}

Errado #2

Certo #2

private void Foo(){

try {//Executa uma operação que lança exceção

} catch (Exception ex) {string Message = ex.Message;throw ex;

}}

private void Foo(){

try {//Executa uma operação que lança exceção

} catch (Exception ex) {string Message = ex.Message;throw;

}}

Logging/Debugging

var exemplo = (x => x.Log4Net)private void Log(string message){

ILog log = LogManager.GetLogger(“MyLoggerName”); log.Info(“Debug message”);log.Error(“A big error!”);

}

<log4net> <!-- A1 is set to be a ConsoleAppender --> <appender name=“MyAppender" type="log4net.Appender.ConsoleAppender">

<!-- A1 uses PatternLayout --> <layout type="log4net.Layout.PatternLayout">

<conversionPattern value=“%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" /> </layout>

</appender> <!-- Set root logger level to DEBUG and its only appender to A1 --> <root>

<level value="DEBUG" /> <appender-ref ref="A1" />

</root> </log4net>

Contato Email: antonio.zegunis@fnac.com.br ou me@tucaz.net Blog: http://blog.tucaz.netTwitter: http://www.twitter.com/tucaz

Referênciashttp://msdn.microsoft.com/en-us/library/ff647787.aspxhttp://msdn.microsoft.com/en-us/library/ff649308.aspxhttp://msdn.microsoft.com/en-us/library/ms229014%28VS.80%29.aspxhttp://blog.tucaz.net/en/2009/07/21/basic-stuff-handling-exceptions-in-net/http://logging.apache.org/log4net/release/manual/configuration.htmlhttp://haacked.com/archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspxhttp://intrafnac.fnac.br/dosi/sistemas/WikiSistemas/Paginas%20Wiki/Home.aspxhttp://intrafnac.fnac.br/dosi/sistemas/WikiSistemas/Paginas%20Wiki/Tratamento%20de%20Exceções.aspx

top related