Skip to content

Instantly share code, notes, and snippets.

View FacileTechnolab's full-sized avatar
:octocat:
happy to help

FacileTechnolab FacileTechnolab

:octocat:
happy to help
View GitHub Profile
@FacileTechnolab
FacileTechnolab / Apphost.cs
Created April 23, 2017 05:06
Configure NLog in servicestack
//requires package installation
//install-package ServiceStack.Logging.NLogger;
//requires using statements
//using ServiceStack.Logging.NLogger;
//using ServiceStack.Logging;
//add this to public override void Configure(Container container) method
LogManager.LogFactory = new NLogFactory();
container.Register<ILog>(ctx => LogManager.LogFactory.GetLogger(typeof(IService)));
PM> Install-Package ServiceStack.Api.Swagger
PM> Install-Package ServiceStack.Logging.NLog
//contructor inject example
public class SomeClass
{
public ILog Logger { get; set; }
public SomeClass(ILog _logger)
{
Logger = _logger;
}
//resolve ILog object in method
public SomeMethod()
//4. setup custom routes for login and log out
Dictionary<Type, string[]> serviceRoutes = new Dictionary<Type, string[]>();
serviceRoutes.Add(typeof(AuthenticateService), new[] { "/Account/Login", "/Account/{Provider}" });
authFeature.ServiceRoutes = serviceRoutes; //specify manual auth routes
//5. Exclude Role and Registration related services
authFeature.IncludeAssignRoleServices = false;
authFeature.IncludeRegistrationService = false;
//6. setup other properties
authFeature.GenerateNewSessionCookiesOnAuthentication = true;
authFeature.DeleteSessionCookiesOnLogout = true;
//AppHost.cs, Configure method
AuthFeature authFeature = new AuthFeature(() => new UserSession(), new IAuthProvider[] {
container.Resolve<IAuthProvider>(),
new JwtAuthProvider(AppSettings) //=> use DI to register
{
AuthKeyBase64 = ConfigurationManager.AppSettings["jwt.AuthKeyBase64"],
RequireSecureConnection = false, //dev configuration
EncryptPayload = false, //dev configuration
HashAlgorithm = "HS256"
}
JsConfig.AssumeUtc = true;
JsConfig<DateTime>.SerializeFn = time => new DateTime(time.Ticks, DateTimeKind.Local).ToString("o");
JsConfig<DateTime?>.SerializeFn = time => time != null ? new DateTime(time.Value.Ticks, DateTimeKind.Local).ToString("o") : null;
JsConfig.DateHandler = DateHandler.ISO8601;
<nlog throwExceptions="true" throwConfigExceptions="true" internalLogLevel="Trace" autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target name="file" xsi:type="File" fileName="${basedir}/Logs/Logs.log" layout="${date}: ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" archiveFileName="${basedir}/archives/log.{#####}.txt" archiveAboveSize="1024" archiveNumbering="Sequence" concurrentWrites="true" keepFileOpen="false" encoding="iso-8859-2" />
</rules>
</nlog>
@FacileTechnolab
FacileTechnolab / Apphost.cs
Created June 15, 2018 10:10
Faciltechnolab/AppHost-AutoQueryGlobalPageSizeFilter
this.GlobalRequestFilters.Add((req, res, requestDto) =>
{
if (requestDto != null && requestDto is QueryBase)
{
var dto = requestDto as QueryBase;
if (dto.Take == null)
{
dto.Take = 100;
}
}
@FacileTechnolab
FacileTechnolab / gist:49ffc4e929b30c43d223b6d5649561a0
Last active June 15, 2018 11:58
Apphost AutoQuery Configure
Plugins.Add(new AutoQueryFeature()
{
MaxLimit = 100
}