Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Thursday, August 26, 2010
( Debug )

From a SO question:

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello world");
string value = SendEmail("");
}

static string SendEmail(string subject)
{
#region Parameter assertions
Debug.Assert(subject != "");
#endregion
return subject;
}
}
}

 

 


Put Debug.Assert() everywhere in the code where you want have sanity checks to ensure invariants. When you compile a Release build (i.e., no DEBUG compiler constant), the calls to Debug.Assert() will be removed so they won't affect performance.

You should still throw exceptions before calling Debug.Assert(). The assert just makes sure that everything is as expected while you're still developing.

http://stackoverflow.com/questions/129120/when-should-i-use-debug-assert

Comments [0] | | # 
# Tuesday, August 24, 2010
( Log4Net )

http://logging.apache.org/log4net/index.html

Logging to the console in a console app: (thanks to http://www.beefycode.com/?tag=/log4net for the great examples)

static void Main(string[] args)
{
log4net.Config.BasicConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));

log.Debug("Hello World!");
log.Info("I'm a simple log4net tutorial.");
log.Warn("... better be careful ...");
log.Error("ruh-roh: an error occurred");
log.Fatal("OMG we're dooooooomed!");

Console.ReadLine();
}

Using app.config

image

<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.SimpleLayout" />
</appender>

<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>

notice level is set to INFO only.

Appenders

An object that persists the log messages somewhere.

eg AdoNetAppender, ConsoleAppender, ColoredConsoleAppender, EventLogAppender, FileAppender (don’t use), RollingFileAppender, SmtpAppender

image

Layout

All the different options:

http://www.beefycode.com/post/Log4Net-Tutorial-pt-4-Layouts-and-Patterns.aspx

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%line %date %-5level %logger - %message%newline" />
</layout>
image

Real Life

class Program
{
private static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
Log.Info("this is an info message");
MyClass.WriteLog();

Console.ReadLine();
}
}

class MyClass
{
private static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public static void WriteLog()
{
Log.Info("this is an info message");
}
}

image

Shows us which class called the logger.

Web Apps

Putting this in AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator()]

Connection Strings and AdoNetAppender

bufferSize value=”1” – otherwise it won’t write each one seperatly

This proved hard

http://weblogs.asp.net/drnetjes/archive/2005/02/16/374780.aspx

doing a search and replace here didn’t work

Nor did extending the provider

http://stackoverflow.com/questions/2441359/can-you-pull-the-connectionstring-for-a-log4net-adonetappender-from-elsewhere-in

** this could be better: http://blog.dynamicprogrammer.com/CommentView,guid,357a3fbe-59e7-4dd4-846a-89083e903532.aspx

Recommended Practice in Code

http://www.beefycode.com/post/Log4Net-Recommended-Practices-pt-1-Your-Code.aspx

Whenever you catch an exception, log it.

Internal Log4Net Logging

When trying to figure out why somethings aren’t working (eg connection strings)

In web.config:

<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>

Comments [0] | | # 
( DNS )

nslookup

server 58.28.4.2 (this is World Exchange’s primary DNS in my case)

set q=MX  - this will give the MY record

mydomain.com

 

set q=A   - this will give the A record

CNAME, HINFO, PTR are all other queries

Comments [0] | | # 
# Thursday, August 19, 2010
# Wednesday, August 11, 2010

http://blog.hmobius.com/post/2010/02/17/ASPNET-40-Part-4-Config-Transformation-Files.aspx

A very good blog on transforms

image

Am transforming Connection strings now and Smtp

<connectionStrings>
<add name="Sitefinity" connectionString="Data Source=mssql1.blah.nz;Initial Catalog=secret;Persist Security Info=True;User ID=user;Password=password!"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

smtp:

<system.net>
<mailSettings>
<smtp from="dave@blah.co.nz">
<network port="25" host="mail.blah.co.nz" userName="user@blah.co.nz" password="secret" xdt:Transform="SetAttributes" xdt:Locator="Match(port)" />
</smtp>
</mailSettings>
</system.net>

Comments [0] | | # 
# Tuesday, August 10, 2010

http://thedatafarm.com/blog/tools/asp-net-iis6-network-service-and-sql-server/

On the master database:

exec sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'

Then go to Management Studio, and add in this user.

Comments [0] | | # 
# Monday, August 09, 2010

http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/javascript-files.aspx

<script src="<%=HttpContext.Current.Request.ApplicationPath.EndsWith("/") ? HttpContext.Current.Request.ApplicationPath : HttpContext.Current.Request.ApplicationPath + "/" %>Res/Scripts/jquery-1.3.2.min.download.js" type="text/javascript"> </script> 

I had a strange bug in Chrome where the css didn’t load properly using this in the masterpage.

<Scripts>
           <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
           <asp:ScriptReference Path="~/javascript/jquery.colorbox.js" />
</Scripts>

This may have been a timing issue as I am now getting jquery from my website and not google.

Comments [0] | | # 
# Saturday, August 07, 2010

Makes it easier to deploy in VS2010 (using web.debug.config and web.release.config)

From the instructions here:

http://www.sitefinity.com/devnet/forums/sitefinity-3-x/set-up-installation/installing-sitefinity-as-a-web-application-in-visual-studio.aspx

The biggest part is that SiteFinity uses User Profiles which are not available at design time in a web application (therefore it doesn’t compile).  To get around this we use the Web Profile Builder, which is a wrapper class which acts as a workaround.

This was the only code I had issue with:

//ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

WebProfile profile = new WebProfile(WebProfile.Create(CreateUserWizard1.UserName, true));
 
Then we convert to a Web Application.  The major difference is that in web sites each page has its code-behind compiled into a seperate library, whereas in a web application all code behind gets compiled into a single library.

There is a secondary file too called yourpage.aspx.designer.cs which moves all of the control declarations into it (a partial class).  This allows VS2k5, 2k8, 2010 to generate code without dumping into the main .cs class, and allows the class access to the controls on the page.

Used FileZilla and it all works.  Now, next post on VS2010 publishing / deploying!

Comments [0] | | # 
# Thursday, August 05, 2010

I’m getting data using LINQ to SQL, then showing on the front end.  If I want a null coming from the database to default to something:

<telerik:GridTemplateColumn HeaderText="Image" UniqueName="Image">  
<ItemTemplate>
<asp:Label ID="asdf" runat="server" Text='<%# String.IsNullOrEmpty(Convert.ToString(Eval("Image1"))) ? "noImage.jpg" : Eval("Image1")%>'></asp:Label>
<a href="<%=VirtualPathUtility.ToAbsolute("~/")%>showFrontEndMaterialDetail.aspx?materialId=<%# Eval("Id")%>">
<img src="<%=VirtualPathUtility.ToAbsolute("~/")%>Images/Uploaded/Thumbs/<%# Eval("Image1") ?? "noPhoto.jpg" %>"></img></a>

</ItemTemplate>
</telerik:GridTemplateColumn>


Thanks to these people:
 

http://stackoverflow.com/questions/3410942/linq-to-sql-default-value-nullable

Comments [0] | | #