gdfgdfhgfh
Build Pipeline Architect
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial, I will teach you how to create a log file in c#.net. Writing a log is very important in every transaction that has been made. In this way you can track if the transaction has an error and how to determine where the error occurs. See the procedure below.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application in c#.
Step 2
Add a Button inside the form.
Step 3
Go to the code view and create a method for creating a log file.
Step 4
Write this code for the button.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application in c#.

Step 2
Add a Button inside the form.

Step 3
Go to the code view and create a method for creating a log file.
- public
static
void
WriteLog(
string
logMessage)
- {
- string
stringLogPath =
@"C:\TransactionLogs\ActionLog-"
+
System
.
DateTime
.
Today
.
ToString
(
"MM-dd-yyyy"
)
+
"."
+
"txt"
;
- FileInfo log_FileInfo =
new
FileInfo(
stringLogPath)
;
- DirectoryInfo log_DirInfo =
new
DirectoryInfo(
log_FileInfo.
DirectoryName
)
;
- if
(
!
log_DirInfo.
Exists
)
log_DirInfo.
Create
(
)
;
- using
(
FileStream file_Stream =
new
FileStream(
stringLogPath, FileMode.
Append
)
)
- {
- using
(
StreamWriter log =
new
StreamWriter(
file_Stream)
)
- {
- log.
WriteLine
(
logMessage)
;
- }
- }
- }
Step 4
Write this code for the button.
- private
void
button1_Click(
object
sender, EventArgs e)
- {
- WriteLog(
"The button is clicked!"
)
;
- }
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.