It takes key and value combination.
<appSettings>
<add key="ServerURI" value="http://localhost:1643/"/>
appSettings>
To read value from web.config
string configPath = ConfigurationManager.AppSettings[key].ToString();
It takes key and value combination.
<appSettings>
<add key="ServerURI" value="http://localhost:1643/"/>
appSettings>
To read value from web.config
string configPath = ConfigurationManager.AppSettings[key].ToString();
1. Add following line to web.config file.
<connectionStrings>
<add name="Name" connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Persist Security Info=True;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/>
connectionStrings>
Name = Provide any name of connection string.
Data Source = Server name. ex: SHUVRO\SQLEXPRESS
Initial Catalog = Database name. Ex: PCDB
2. Get the connection string from web.config file from cs
String ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Name"].ConnectionString;
[“Name”] is the connection string name that is in web.config
To add log4net in web project steps are below:
1. Download and log4net dll in project where you want to use it.
2. We can write log in log file or we can send mail when an error occur. For these two options we have to make setup in Web.config file. Initially add following line after
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
a. Write log in log file only, add following code in web.config file. You can change the log file name “PC.log.txt” is the file name here.
<log4net debug="true">
<appender name="RollingLogFileAppender
type="log4net.Appender.RollingFileAppender">
<file value="App_Data\PC.log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
layout>
appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
root>
log4net>
b. Send log through mail need to add following line to web.config. In
<log4net debug="true">
<appender name="SmtpAppender" type="log4netExtensions.SmtpClientSmtpAppender">
<to value="e-mail,e-mail" />
<from value="e-mail" />
<subject value="subject" />
<smtpHost value="smtp.gmail.com" />
<port value="587"/>
<authentication value="Basic" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ALL"/>
evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
layout>
appender>
<logger name="PC.Web.Smtp">
<level value="All" />
<appender-ref ref="SmtpAppender" />
logger>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
root>
log4net>
C. Combinly add both facility to web config add both appender in web.config file
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="App_Data\PC.log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
layout>
appender>
<appender name="SmtpAppender" type="log4netExtensions.SmtpClientSmtpAppender">
<to value="e-mail,e-mail />
<from value="e-mail" />
<subject value="subject" />
<smtpHost value="smtp.gmail.com" />
<port value="587"/>
<authentication value="Basic" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ALL"/>
evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
layout>
appender>
<logger name="PC.Web.Smtp">
<level value="All" />
<appender-ref ref="SmtpAppender" />
logger>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
root>
log4net>
3. Now Add below line in AssebmlyInfo.cs file of web project
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
4. Add below line in cs file where you are going to use it.
a. To write log in log file:
protected static log4net.ILog _Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
b. To send mail:
protected static log4net.ILog _Logger = log4net.LogManager.GetLogger("PC.Web.Smtp");
Now _Logger object can be use. There are various method like Debug(), Info() etc.
Tool: This is an open source tools. Which will give you an easy way to make your installer. NSIS software download link:
http://nsis.sourceforge.net/Download
How it is work: Basically this script will compress your exe, depended dlls, third party software’s, documents etc which is required to run your project. It will produce a single “Setup.exe” file. When you will install this setup file automatically it will write down everything in the computer registry to run your software properly. If you arrange your folder structure like depended dlls, exe, doc files etc. So it will be easy for you to upload that files during installer making.
IDE: There are some IDE to write down the script. But according to me “HM NSIS Edit 2.0.3” is the best one. It will provide you a wizard by clicking you can easily make your installer. Download link of that IDE:
You can choose options according to your requirement. After finishing your wizard you will get some script. But here I will explain some problem that I have faced:
1. When you select multiple language and its correspondence terms of service doc file. It was not working. So in the license page section write down the following line.
; License page
!insertmacro MUI_PAGE_LICENSE "$(MUILicense)"
2. If you want to install third party software you have to use the following code. You have to add it in a section.
Section 'name' SEC01
DetailPrint '..Installing name..'
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File ".\path of software"
ExecWait 'MsiExec.exe /q /i $TEMP\Filename.msi' $0
DetailPrint '.. Name exit code = $0'
Delete '$TEMP\Filename.msi'
SectionEnd
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "Application ApS"
!define PRODUCT_WEB_SITE "http://www.Application.dk"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\Application.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_APP_REGKEY "Software\Application ApS\Application"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
; MUI 1.67 compatible ------
!include "MUI2.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON ".\Application.ico"
!define MUI_UNICON ".\Application.ico"
!define MUI_TEXT_COLOR "FFFFFF"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP ".\SB_Setupbar_Top.bmp"
!define MUI_HEADERIMAGE_UNBITMAP ".\SB_Setupbar_Top.bmp"
!define MUI_HEADER_TRANSPARENT_TEXT
; !define MUI_BGCOLOR "808080"
; MUI Settings / Wizard
!define MUI_WELCOMEFINISHPAGE_BITMAP ".\SB_Setupbar_Left.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP ".\SB_Setupbar_Left.bmp"
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE "$(MUILicense)"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Start menu page
var ICONS_GROUP
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Application"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\Application.exe"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Danish"
; License Language
LicenseLangString MUILicense ${LANG_ENGLISH} ".\SoftwareLicenseEnglish.rtf"
LicenseLangString MUILicense ${LANG_DANISH} ".\SoftwareLicenseDansk.rtf"
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
;RequestExecutionLevel admin
InstallDir "$PROGRAMFILES\Application"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails hide
ShowUnInstDetails hide
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Section 'RuntimeRequisite' SEC01
DetailPrint '..Installing RuntimeRequisite'
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File ".\debug\RuntimeRequisite\RuntimeRequisite.msi"
ExecWait 'MsiExec.exe /q /i $TEMP\RuntimeRequisite.msi' $0
DetailPrint '..RuntimeRequisite exit code = $0'
Delete '$TEMP\RuntimeRequisite.msi'
SectionEnd
Section "Application" SEC02
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File ".\debug\QtCored4.dll"
File ".\debug\QtWebKitd4.dll"
File ".\Application.exe"
File ".\Application_en.qm"
File ".\Application_dk.qm"
SectionEnd
section Shortcut
; Shortcuts
SetShellVarContext all
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath "$INSTDIR"
CreateShortCut "$DESKTOP\Application.lnk" "$INSTDIR\Application.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section -AdditionalIcons
SetShellVarContext all
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Application.lnk" "$INSTDIR\Application.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\Application.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\Application.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
StrCmp $LANGUAGE ${LANG_DANISH} 0 english
WriteRegStr HKCU "${PRODUCT_APP_REGKEY}" "language" "danish"
Goto done
english:
StrCmp $LANGUAGE ${LANG_ENGLISH} 0 done
WriteRegStr HKCU "${PRODUCT_APP_REGKEY}" "language" "english"
done:
SectionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "Application was successfully removed from your computer."
FunctionEnd
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove Application and all of its components?" IDYES +2
Abort
FunctionEnd
Section Uninstall
SetShellVarContext all
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\Application.exe"
Delete "$INSTDIR\ QtCored4.dll"
Delete "$INSTDIR\ QtWebKitd4dll"
RMDir /r "$INSTDIR\debug"
RMDir /r "$APPDATA\Application"
SetShellVarContext all
Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"
Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk"
Delete "$DESKTOP\Application.lnk"
Delete "$SMPROGRAMS\$ICONS_GROUP\Application.lnk"
RMDir "$SMPROGRAMS\$ICONS_GROUP"
RMDir "$INSTDIR"
ExecWait 'MsiExec.exe /q /X{88164D59-4FFD-4874-93BC-5E001A7938F3}' $0
DetailPrint '..RuntimeRequisite exit code = $0'
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
DeleteRegKey HKEY_CURRENT_USER "Software\Application ApS"
SetAutoClose true
SectionEnd