Hi, Is it possible to logging the error log into Local drive either ( c: or d: ) after hosting the application in iis . if anyone knows this,
suggest me with example code.
Thanking you,
Karthik.K
Hi, Is it possible to logging the error log into Local drive either ( c: or d: ) after hosting the application in iis . if anyone knows this,
suggest me with example code.
Thanking you,
Karthik.K
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Jul 10, 2023, 9:36 AM
It is generally not possible to directly save logs to the end user's local system using NLog or any other server-side logging framework. When hosting an application in IIS, the application runs on the server, and the log files are stored on the server's file system.
Karthik KPosted Jul 10, 2023, 9:12 AM
@amit ,
will it write into end user local System ? after we host the appplication in IIS ? i would like to have like this .
to write the error into logfile.even after host the webpplication in iis.
Thanks
Amit MohantyPosted Jul 10, 2023, 8:49 AM
nlog.config:In your code files, you can now use NLog to log messages. For example:
Karthik KPosted Jul 10, 2023, 7:43 AM
@ Rawat ,
Thanks for the quick reply. currently we have using the asp,net. Not a Asp.net core application. could you please suggest me the in asp.net?
Thanks
Deepak RawatPosted Jul 10, 2023, 7:33 AM
In your ASP.NET Core project, open the
appsettings.jsonfile and add a new section for logging configurationwe have specified the file path as
"C:\\Logs\\error.log"for logging errors to theerror.logfile in theC:\Logsdirectory. You can change the file path and name as per your preference.Startup.csfile, configure logging in theConfigureServicesmethodwe are using the
AddFileextension method from a third-party logging provider (such asSerilog.Extensions.Logging.File). Make sure you have the necessary NuGet package installed for the file logging functionality.ILoggerinto your classes where you want to log errors and use it to log errorswe inject
ILoggerinto the constructor ofYourClassand then use_logger.LogErrorto log an error with the exception details and a message.With the above configuration, any errors logged using the logger will be written to the specified file path (
C:\Logs\error.login our example) on the local drive. Make sure the application has appropriate write permissions to create and write to the specified file path.