Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

c# - Trace file isn't being created even though TraceEvent is called?

Objective

Use System.Diagnostics to perform tracing. Though I have used log4net and other logging solutions, I am only interested in getting tracing to work with System.Diagnostics.

Problem

Even though I'm issuing the TraceEvent the file is not being created anywhere.

Application Information

I have an application that's hosting some WF services. One of the services is a state machine with an initial state that looks like this:

State Machine Initial State

the LogMessage custom activity is also very straight forward. It receives four basic parameters:

LogMessage Parameters

defines the TraceSource as a variable:

LogMessage TraceSource Variable

and then simply calls TraceEvent:

LogMessage TraceEvent Invocation

Configuration

The configuration for this TraceSource and TraceListener is as follows:

  <system.diagnostics>
    <trace autoflush="true"/>
    <sources>
      <source name="log" switchValue="All">
        <listeners>
          <add name="file" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
               BaseFileName="gsf_workflows.txt"
               DiskSpaceExhaustedBehavior="ThrowException"
               Location="Custom"
               CustomLocation="D:Log"
               MaxFileSize="81920000"
               LogFileCreationSchedule="LogFileCreationScheduleOption.Daily"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

FYI for everyone stumbling on this page..

FileLogTraceListener will not create folders if they are missing.

FileLogTraceListener will not bypass security, your process identity will need create+modify permissions on the target folder.

It's "bad form" to target the executable folder, this tends to change depending on the host (for example, when writing under IIS Express you aren't writing to the same location as DevEnv, nor the hosted web app.) One suggestion is that instead of "ExecutableLocation" you may want to opt for "Custom" and specify a particular path (such as X:logfiles)

Writers flush to disk when their internal buffers fill, if memory serves me the default buffer size is 8KB. This is not a facet of trace listeners, but the underlying file stream it writes to.

Lastly, if you do not need the form and function of FileLogTraceListener, instead consider tracing to the EventLog (there is a listener for this) as this may be more accessible to other devs and non-devs (such as ops engineers, third party monitoring tools, etc.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...