Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
💭
Developing

Randle csharpforevermore

💭
Developing
View GitHub Profile
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net>
<appender name="OutputDebug" type="log4net.Appender.OutputDebugStringAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
@csharpforevermore
csharpforevermore / OutputTraceTime.cs
Created February 7, 2014 11:48
Logs the time to the trace. Used instead of a tracepoint.
HttpContext.Current.Trace.Write("DEBUG @ " + DateTime.Now.ToString("hh'h' mm'm' ss's' ff'ms'"));
@csharpforevermore
csharpforevermore / ElmahTrim.sql
Created February 9, 2014 14:29
Trim ELMAH database log table. Removes any entries older than 90 days (d = days, 90 = count). Original by Scott Mitchell (founder of 4GuysFromRolla.com)
DELETE FROM [ELMAH_Error]
WHERE TimeUtc < DATEADD(d, -90, getdate())
@csharpforevermore
csharpforevermore / web.config
Created February 9, 2014 14:32
Configure ELMAH so that it logs errors to Twitter.
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
<section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
</sectionGroup>
</configSections>
@csharpforevermore
csharpforevermore / TrimUmbracoLog.sql
Created February 9, 2014 21:09
Reduce size of Umbraco log database table
TRUNCATE TABLE [umbracoLog]
@csharpforevermore
csharpforevermore / ResolveIT.cmd
Created February 10, 2014 12:37
Get the DNS name of a server at IP 10.10.10.10
NBTSTAT -A 10.10.10.10
@csharpforevermore
csharpforevermore / ConfigurationHelper.cs
Created February 12, 2014 14:56
Get a strongly-typed appsetting value
public static T GetAppSetting<T>(string key, T defaultValue)
{
var reader = new AppSettingsReader();
try
{
return (T)reader.GetValue(key, typeof(T));
}
catch (InvalidOperationException)
{
@csharpforevermore
csharpforevermore / ReplaceStringCaseInsensitive.cs
Created February 12, 2014 17:06
Like String.Replace but can do so with regards to case and culture.
using System;
using System.Text;
public static class ExtensionMethods
{
/// <summary>
/// Case insensitive string replacement
/// </summary>
/// <param name="str">string to process</param>
/// <param name="oldValue">old value to find</param>
@csharpforevermore
csharpforevermore / DictionaryStringStringToString
Created February 13, 2014 05:16
Dictionary<string, string> to a single string with commas separating the keyvaluepairs
string s = string.Join(",", myDict.Select(x => x.Key + "=" + x.Value).ToArray());
@csharpforevermore
csharpforevermore / ListAllCachedUmbracoMacros.sql
Created February 17, 2014 09:19
In Umbraco, sometimes you want to know how many macros have caches. This query will tell you how long has been set on each macro.
/****** Script for SelectTopNRows command from SSMS ******/
SELECT *
FROM [dbo].[cmsMacro]
WHERE macroRefreshRate > 0