TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
L A
NA
170
171.2k
Trace, Log to file
Jul 7 2018 4:07 PM
Hi, I'm working on ASP.Net MVC web app, using System.Diagnostics.TraceSource to trace and log to file. Added following to web.config
<
system.diagnostics
>
<
trace
autoflush
=
"false"
indentsize
=
"4"
>
</
trace
>
// what's this for?
<
sources
>
<
source
name
=
"WebAppLog"
>
<
listeners
>
<
add
name
=
"FileLog"
type
=
"System.Diagnostics.TextWriterTraceListener"
initializeData
=
"PartialView_WebApp.log"
traceOutputOptions
=
"DateTime,ThreadId,ProcessId,Timestamp,LogicalOperationStack,Callstack"
>
<
filter
initializeData
=
"All"
type
=
"System.Diagnostics.EventTypeFilter"
/>
</
add
>
<
remove
name
=
"Default"
/>
</
listeners
>
</
source
>
</
sources
>
</
system.diagnostics
>
Added Log.cs to application to log mesages to file.
public
class
Log
{
static
TraceSource source =
new
TraceSource(
"WebAppLog"
);
public
static
void
Message(TraceEventType traceEventType,
string
message)
{
short
id;
switch
(traceEventType)
{
case
TraceEventType.Information:
id = 3;
break
;
case
TraceEventType.Verbose:
id = 4;
break
;
default
:
id = -1;
break
;
}
source.TraceEvent(traceEventType, id, message);
source.Flush();
}
}
Home controller.cs
public
ActionResult Index()
{
try
{
Log.Message(System.Diagnostics.TraceEventType.Information,
"Index Action Start"
);
// Do work
Log.Message(System.Diagnostics.TraceEventType.Information,
"Index Action End"
);
return
View();
}
catch
(Exception ex)
{
throw
;
}
}
After executing, i'm able to generate log file but couldn't write anything, always the file size is 0 bytes. What could be the possible mistake.?
Reply
Answers (
2
)
Create table dynamically in database using c# code
Connecting visual studio 2017 to 64-bit excel file