Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active April 13, 2018 12:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kkoziarski/7b6962323cd44482099f038dad4ec336 to your computer and use it in GitHub Desktop.
JSNLog sample demo
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsnlog/2.26.1/jsnlog.js"></script>
</head>
<body>
<script>
// JL.setOptions({
// "defaultAjaxUrl": "http://localhost:53676/jsnlog.logger "
// });
// JL().info("log message");
JL.setOptions({
"defaultAjaxUrl": "http://localhost:53676/jsnlog.logger"
});
let logger = JL();
logger.setOptions({
"url": "http://localhost:53676/jsnlog.logger"
});
logger.fatal('test message');
function sendJSNLogEvent() {
JL.setOptions({
"defaultAjaxUrl": "http://localhost:53676/jsnlog.logger"
});
let logger = JL();
logger.setOptions({
"url": "http://localhost:53676/jsnlog.logger"
});
logger.fatal('test message');
}
</script>
</body>
</html>
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace JSNLogCore.Demo
{
public class Startup
{
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// ....
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
var jsnlogConfiguration = new JsnlogConfiguration
{
corsAllowedOriginsRegex = ".*",
defaultAjaxUrl = "jsnlog.logger",
serverSideMessageFormat = "%date | %requestId | %userAgent| %logger | %url | %userHostAddress | %level | %message"
};
jsnlogConfiguration.corsAllowedOriginsRegex = true ? jsnlogConfiguration.corsAllowedOriginsRegex : this.Configuration["JSNLog:corsAllowedOriginsRegex"];
app.UseJSNLog(new LoggingAdapter(loggerFactory), jsnlogConfiguration);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async context =>
{
await context.Response.WriteAsync(@"
<!DOCTYPE html>
<html lang=""en"">
<head>
<meta charset=""UTF-8"">
<title>JSNLog</title>
<script type=""text/javascript"" src=""https://cdnjs.cloudflare.com/ajax/libs/jsnlog/2.22.1/jsnlog.min.js""></script>
<script type=""text/javascript"">
JL.setOptions({
""defaultAjaxUrl"": ""/jsnlog.logger""
});
</script>
</head>
<body>
<h1>Page with js error</h1>
<script>
foo();
</script>
</body>
</html>
");
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment